On Wednesday, October 10, 2012 3:28:45 PM UTC+1, Colin Law wrote:
>
> On 10 October 2012 08:47, paul h <[email protected] <javascript:>> 
> wrote: 
> > Hi, 
> > 
> > rails 3.2.8 
> > 
> > I must be missing something basic (and it's been driving me mad) because 
> I 
> > am trying to send one additional data attribute to my controller from a 
> > link, but I can't seem to get it into the params received by the 
> controller. 
> > 
> > I have looked around and found answers, but none seem to affect my 
> links. 
> > 
> > I've set up a dummy app with a home page and a single link to a contacts 
> > page - here is the code: 
> > 
> > routes.rb 
> > 
> > root :to => 'home#index', :as => 'home' 
> > resource 'contacts' 
> > 
> > Haml Home Page View 
> > 
> > # I want to be able to display 'bar' on the contacts page 
> > = link_to "Contacts", contacts_path, :data => {:foo => 'bar'} 
> > 
> > The generated html link: 
> > 
> > <a href="/contacts" data-foo="bar">contacts</a> 
> > 
> > But I don't receive the foo attribute in the params object in the show 
> > action of ContactsController. 
> > 
> > If I add {:method => :post} to link_to, then it routes to the create 
> action 
> > of the ContactsController but again, foo is missing. 
> > 
> > = link_to "Contacts", contacts_path, {:method => :post, :data => {:foo 
> => 
> > 'bar'}} 
> > 
> > generates: 
> > 
> > <a href="/contacts" data-foo="bar" data-method="post" 
> > rel="nofollow">contacts</a> 
>
> What do you see in development.log when you click the link.  It should 
> show you the parameters being passed.  Also if you do params.inspect 
> what do you see?  You can put that in a view or use a debugger. 
>

Hi Colin,

That's basically what I was doing - passing params.inspect to the view so I 
could see exactly was there.

I wasn't getting anything other than the standard params hash you'd expect 
for a simple link - controller, action, id.

Thanks for the reply. 

>
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/eY70AMA7EAkJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to