Mike McCallen
Mike McCallen

Reputation: 307

Convert html "href=" into "link_to" for Rails 4

This is the code i want to convert into link_to

<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?category=Video+and+animation">Show me everything</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Intro">Intro</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Animation+%26+3D">Animation & 3D</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Editing+and+Post+Production">Editing and Post Production</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Other">Other</a></li>
</ul>

and this is how it looks like

droptdown

How would you convert for example

<li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Intro">Intro</a></li>

Into <%= link_to "Intro", some_path(that goes to the above Url), method: :get %>

Or how would you add this method: :get,to the html href above,i need it for endless scrolling,turbo links is causing problems,so i have to use method: :get

This is the seeds.rb i sued to create the category with its subcategories

@category = Category.create!(name:  "Video and animation")

["Intro", "Animation & 3D", "Editing and Post Production", "Other"].each do |name|

@subcategory = Subcategory.create!(name: name, category_id: @category.id)

end

Upvotes: 1

Views: 806

Answers (1)

Vrushali Pawar
Vrushali Pawar

Reputation: 3803

<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?category=Video+and+animation" data-method="get">Show me everything</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Intro" data-method="get">Intro</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Animation+%26+3D" data-method="get">Animation & 3D</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Editing+and+Post+Production" data-method="get">Editing and Post Production</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="http://www.example.com/gigs?subcategory=Other" data-method="get">Other</a></li>
</ul>

Upvotes: 1

Related Questions