0

I have this link here:

<a href="#rating-box" class="login-window">Rate & Commment</a>

and I would like to convert this into rails style, maybe something like:

<%= link_to 'Rate & Comment', :anchor => "rating-box", :class => "login-window"%>

Is it possible to do so?

Edit 1

One more question.

When I use

<%= link_to "Rate & Commment", comment_path(:post_id => post.id), :class => "post" %>

I can pass on some data (in this case, the post id) to the controller and i can use the data by referencing to params.

So if the path becomes a div element, like

<%= link_to 'Rate & Comment', "#rating-box", :class => "post" %>

can I still pass on data by bracketing it?

Edit 2

I have tried to do this in my view:

<a href="#rating-box" class="post" data-post_id = '<%= p.id %>'>Rate & Comment</a>

However I couldn't retrieve the data in controller with the code below:

def create
@comment.post_id = params[:post_id]
end
Alex Luk
  • 41
  • 9
  • From here: http://stackoverflow.com/questions/18948017/best-way-to-handle-data-attributes-in-slim I think my approach can't work... but how can I use approach 2 as stated in that post to pass on multiple variables? – Alex Luk Sep 01 '15 at 13:53

2 Answers2

0

Conversion of the link in rails style is:

<%= link_to "Rate & Commment", "#rating-box", :class => "login-window" %>
Md Sirajus Salayhin
  • 4,974
  • 5
  • 37
  • 46
  • Documentation [here](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to). – steve klein Aug 27 '15 at 20:18
  • I haven't got enough reputation yet to upvote this but it was helpful, thanks! – Alex Luk Sep 01 '15 at 08:04
  • From here: stackoverflow.com/questions/18948017/… I think my approach can't work... but how can I use approach 2 as stated in that post to pass on multiple variables? – Alex Luk Sep 01 '15 at 14:29
0

At the end I have to use this to solve my own problem:

<%= link_to "Rate & Commment", fetch_rating_path(:post_id => p.id), :class => "login-window" %>
Alex Luk
  • 41
  • 9