Sending parameters to controller via button_to

31 views
Skip to first unread message

Padmahas Bn

unread,
Jul 8, 2015, 7:57:56 PM7/8/15
to rubyonra...@googlegroups.com
I have 

<%= label_tag :"Enter member code" %>
<%= text_field_tag :membercode%>

<%= button_to "Death/Retired Recovery Letter Printing", recovery_letter_rpts_path(membercode: membercode) %>


In my controller

def create
    membercode = params[:membercode]
    exist = Member.find_by_member_code(membercode)
    respond_to do |format|
      if exist.nil?
        # format.html{ redirect_to new_recovery_url, notice: 'Member not found.'} # here you just echo the result
        puts "******************************************"
        puts "This is the member code #{membercode}"  # done
        puts "******************************************"
        redirect_to(recoveries_path)
      else
        puts "This is the NO member code #{membercode}"
        redirect_to(recoveries_path)
      end
    end    
  end


all I want to do is send membercode which is accepted via text_field_tag to the create action of the controller. And there is no form to contain these fields. I want it that way because, there will be more "button_to" which want to send membercode to different controller's action.


Please help me.

Sadaf Noor

unread,
Jul 9, 2015, 1:59:15 AM7/9/15
to rubyonra...@googlegroups.com
can't you do that using template?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9c16f865-e756-4e91-83ce-b5d101abdfee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
 Md. Sadaf Noor (@sadaf2605)
 www.sadafnoor.com

Padmahas Bn

unread,
Jul 9, 2015, 3:26:05 AM7/9/15
to rubyonra...@googlegroups.com
Can you please elaborate?

James Davis, PhD

unread,
Jul 9, 2015, 8:11:38 AM7/9/15
to rubyonra...@googlegroups.com
Use a form in the view. The form will 'post' the data to the create method in your controller. This is assuming you have the correct routes.
Message has been deleted

Colin Law

unread,
Jul 9, 2015, 2:35:15 PM7/9/15
to rubyonra...@googlegroups.com
Put the field in a form, then you can have multiple submit buttons
within the form.

Colin
Reply all
Reply to author
Forward
0 new messages