Hi, I am new in RoR and i am lost in a simple action. In my home page i am trying to call a create action from a different controller. Here is how i do it: <%= link_to "Join!", :controller => "participants",:action => "create",:user_id => 2,:defi_id => item.id%> What am i doing wrong? It should be a post action, how do i specify that? Thank you for your help Greg -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Do you want to create a Participant? I think you should use POST when you want to create a record in database. Normal a link always a GET request, so maybe you could create a form or use <%= link_to "Join!", participants_path, *:method => :pos*t %>, you could check the api for details On Thu, Mar 25, 2010 at 10:26 AM, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > I am new in RoR and i am lost in a simple action. > In my home page i am trying to call a create action from a different > controller. > Here is how i do it: > > <%= link_to "Join!", :controller => "participants",:action => > "create",:user_id => 2,:defi_id => item.id%> > > > What am i doing wrong? It should be a post action, how do i specify > that? > > Thank you for your help > Greg > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
yong gu wrote: <%= link_to "Join!", participants_path, :method => :post %> I think i should try this as i want to insert a new participant <%= link_to "Participer!", new_participant_path, :method => :post %> But this only redirects me to the page, how do i add the parameters to actually insert data? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
When you click "Join!", you want to create a participant and then redirect to somewhere, is that right? If so, you should post your data to the controller, by using <%= link_to "Participer!", participants_path, :method => :post, *:group_id => @group.id* %>. when you click the link, the ''create'' method in the according controller will be executed. or you could create a form yourself, just put your parameters in the hidden input, as: <form action="/participants"> <input type="hidden" name="paramter" value="value" /> <input type="submit" name="submit" value="Join"/> </form> On Thu, Mar 25, 2010 at 10:55 AM, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> yong gu wrote: > <%= link_to "Join!", participants_path, :method => :post %> > > I think i should try this as i want to insert a new participant > > <%= link_to "Participer!", new_participant_path, :method => :post %> > > But this only redirects me to the page, how do i add the parameters to > actually insert data? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
yong gu wrote:> When you click "Join!", you want to create a participant and then > redirect > to somewhere, is that right? > > If so, you should post your data to the controller, by using <%= link_to > "Participer!", participants_path, :method => :post, > > *:group_id => @group.id* %>. when you click the link, the ''create'' > method > in the according controller will be executed. > > or you could create a form yourself, just put your parameters in the > hidden > input, as: > > <form action="/participants"> > > <input type="hidden" name="paramter" value="value" /> > > <input type="submit" name="submit" value="Join"/> > > </form>Yes i know i could use a form but i prefer to use a link_to. Is it better use a from instead? I did this: <%= link_to "Participer!", new_participant_path, :method => :post,:defi_id => item.id,:user_id => 2 %> but it still doesn''t create the data into de db, it redirects me to the new template. Greg -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
i think it should be <%= link_to "Participer!", *participants_path*, :method =>:post, :defi_id => item.id, :user_id => 2 %> not <%= link_to "Participer!", *new_participant_path*, :method =>:post, :defi_id => item.id, :user_id => 2 %> On Thu, Mar 25, 2010 at 11:24 AM, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> yong gu wrote: > > When you click "Join!", you want to create a participant and then > > redirect > > to somewhere, is that right? > > > > If so, you should post your data to the controller, by using <%= link_to > > "Participer!", participants_path, :method => :post, > > > > *:group_id => @group.id* %>. when you click the link, the ''create'' > > method > > in the according controller will be executed. > > > > or you could create a form yourself, just put your parameters in the > > hidden > > input, as: > > > > <form action="/participants"> > > > > <input type="hidden" name="paramter" value="value" /> > > > > <input type="submit" name="submit" value="Join"/> > > > > </form> > > Yes i know i could use a form but i prefer to use a link_to. Is it > better use a from instead? > > > I did this: > <%= link_to "Participer!", new_participant_path, :method => > :post,:defi_id => item.id,:user_id => 2 %> > > but it still doesn''t create the data into de db, it redirects me to the > new template. > > > Greg > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yong Gu wrote:> i think it should be > > <%= link_to "Participer!", *participants_path*, :method =>:post, > :defi_id => > item.id, :user_id => 2 %> > > not > > <%= link_to "Participer!", *new_participant_path*, :method =>:post, > :defi_id > => item.id, :user_id => 2 %>Thanks we are on the good track. But there is a last problem, the parameters arent posted. I''ve checked with firebug. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yong Gu
2010-Mar-25 03:40 UTC
Re: Re: Re: Re: Call a controller action from a different view
so how about using button_to? I think this could be useful for you http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597 On Thu, Mar 25, 2010 at 11:36 AM, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Yong Gu wrote: > > i think it should be > > > > <%= link_to "Participer!", *participants_path*, :method =>:post, > > :defi_id => > > item.id, :user_id => 2 %> > > > > not > > > > <%= link_to "Participer!", *new_participant_path*, :method =>:post, > > :defi_id > > => item.id, :user_id => 2 %> > > Thanks we are on the good track. But there is a last problem, the > parameters arent posted. I''ve checked with firebug. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Ma
2010-Mar-25 03:49 UTC
Re: Re: Re: Re: Call a controller action from a different view
Yong Gu wrote:> so how about using button_to? > > I think this could be useful for you > > http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597I''ve replaced link_to by button_to and it does the same thing. Do i HAVE TO use a form_for? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Mar-25 08:47 UTC
Re: Re: Re: Re: Call a controller action from a different view
On 25 March 2010 03:36, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Yong Gu wrote: >> i think it should be >> >> <%= link_to "Participer!", *participants_path*, :method =>:post, >> :defi_id => >> item.id, :user_id => 2 %> >> >> not >> >> <%= link_to "Participer!", *new_participant_path*, :method =>:post, >> :defi_id >> => item.id, :user_id => 2 %> > > Thanks we are on the good track. But there is a last problem, the > parameters arent posted. I''ve checked with firebug.What parameters aren''t posted? If you want additional parameters in the link you will need to include them in the link_to. Have a look at the generated html for the link to check that what you want is there. Where is the data coming from? If it is user input why not use a form with a submit button? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Ma
2010-Mar-26 06:10 UTC
Re: Re: Re: Re: Call a controller action from a different view
Colin Law wrote:> On 25 March 2010 03:36, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> :defi_id >>> => item.id, :user_id => 2 %> >> >> Thanks we are on the good track. But there is a last problem, the >> parameters arent posted. I''ve checked with firebug. > > What parameters aren''t posted? If you want additional parameters in > the link you will need to include them in the link_to. Have a look at > the generated html for the link to check that what you want is there. > > Where is the data coming from? If it is user input why not use a form > with a submit button? > > ColinThere is no user input this is why i prefer using a link. The parameter not posted are :defi_id and user_id -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Mar-26 09:07 UTC
Re: Re: Re: Re: Re: Call a controller action from a different view
On 26 March 2010 06:10, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 25 March 2010 03:36, Greg Ma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> :defi_id >>>> => item.id, :user_id => 2 %> >>> >>> Thanks we are on the good track. But there is a last problem, the >>> parameters arent posted. I''ve checked with firebug. >> >> What parameters aren''t posted? If you want additional parameters in >> the link you will need to include them in the link_to. Have a look at >> the generated html for the link to check that what you want is there. >> >> Where is the data coming from? If it is user input why not use a form >> with a submit button? >> >> Colin > > There is no user input this is why i prefer using a link. The parameter > not posted are :defi_id and user_idWhat does the generated html for the link look like? What do you see in the log file when you click the link? It should show the params. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.