Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:02:05+00:00 2026-05-24T01:02:05+00:00

new to rails so bear with me. What I would like to do, is

  • 0

new to rails so bear with me. What I would like to do, is I have a list of messages on the screen. I want the message to be marked as ‘closed’ which means it just fills in a completeDate.

I have a model:

class Message < ActiveRecord::Base
  attr_accessible :topic, :body, :completeDate, :created_at
  belongs_to :account
  belongs_to :user
  has_many :message_followups
end

I have a controller:

class MessagesController < ApplicationController
def close
   @message = Message.find(params[:messageId])
   @message.completeDate = Date.today
   if @message.save
    redirect_to myHomeMessages_path, :flash => { :success => "Your message was closed." }
   else
    redirect_to myHomeMessages_path, :flash => { :error => "Error closing message." }
   end
end
end

I have a view:

<%= form_for (???) do |f| %>
    Are you sure you wish to close this message?<br>
    <%= hidden_field_tag 'messageId', message.id.to_s %>
    <%= submit_tag "Close Message" %>
<% end %>

I’m having a problem figuring out how to get the form_for or a form_tag to call the specific method ‘close’ in the messages controller. Any help would be greatly appreciated, thanks.

Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:02:06+00:00Added an answer on May 24, 2026 at 1:02 am

    A very important hint, you should not use camel case for variable names on Ruby, variable sand methods should use underscore as separators, if you’re coming from another language like Java, try to avoid using the same naming patterns you used in there. Camel case in ruby is only for class and module names.

    I am guessing you’re using Ruby on Rails 3, as you haven’t said what you’re using. First, you need a route for that, it would look like this on your routes.rb file:

    resources :messages do
        member do 
            post 'close'
        end
    end
    

    A little change to your controller

    def close
       @message = Message.find(params[:id]) #you don't need to use the hidden field here
       @message.completeDate = Date.today
       if @message.save
        redirect_to myHomeMessages_path, :flash => { :success => "Your message was closed." }
       else
        redirect_to myHomeMessages_path, :flash => { :error => "Error closing message." }
       end
    end
    

    And your form is going to look like this:

    <%= form_for( @message, :url => close_message_path( @message ), :html => { :method => :post } ) do |f| %>
        Are you sure you wish to close this message?<br>
        <%= f.submit "Close Message" %>
    <% end %>
    

    This form is going to be posted to “/messages/ID_HERE/close” and Rails is going to set the “ID_HERE” value as the “id” parameter on your request.

    You can see the full documentation about form_for here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Ruby and Rails so bear with me please. I have
Starting a new rails project and we have a well-thought-out color palette, and want
I am new to Rails, so bear with me, I need to have apache
new rails user here. I have a rails project that I want to accept
I have this new Rails app. I installed Devise. I don't want people registering
I have a new rails app which needs to access data from a legacy
I have a new rails application which I have created under Windows 7 by
I have a new rails app with a fresh database and I want to
I'm a completely new rails developer so bear with me :-) I have two
Relatively new rails programmer here, so bear with me. I have an app where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.