Using a rails delete method in an html link? - html

I need to change this to HTML and have no idea how to put the delete route in a normal a tag, any ideas? Thanks
<li><%= link_to "Link", user_photo_pin_path(user_id: #user.id, photo_id: #photo.id, id: {{id}} ) , method: :delete, data: { confirm: 'Quieres borrar esto?'} %></li>

You can use something like "pry-rails" or "debugger" gems. Set up "debugger" method in your view and execute any of ActionView:Helpers like link_to or form_tag and see what html returned by this methods.

Related

how to set an unique id for link_to tag in rails?

I need to separate unique ids for some linking purpose, I just want to know how to make an unique id for link_to?
Like I am using:
<%= link_to "Edit", edit_question_path(question.id),method: :get, :remote => true, :id => #question.id%>
This didn't work then I tried:
<%= link_to "Edit", edit_question_path(question.id),method: :get, :remote => true, id: myBtn_<%=question.id%> %>
Nothing worked. Is there any solution?
Try with:
<%= link_to 'Edit',
edit_question_path(question.id),
method: :get,
remote: true,
id: "myBtn_#{question.id}" %>
You need to see what's the way to access a question variable, as instance or local one (I used a question, as you're doing with the path), and myBtn_<%=question.id%> won't work if you don't have defined a myBtn variable, even less if you try to include erb tags to print inside the erb open-close for the link_to.

link_to helper weird url

Hello everyone I was wondering how I can get rid of this ugly url that was generated when I clicked a link on my website. It looks like this:
http://www.imaaroncs.com/about?as=AboutMe&class=changeMe&controler=welcome
I want it to just say about but I do not know how to do it with the link_to rails helper this is what I have so far:
<li class="navbar-brand"><%= link_to "About Me", class: "changeMe",controler: "welcome", as: "AboutMe", action: "about"%>
You're sending a few parameters you don't need (the ones after ? are being interpreted as additional query params)
<%= link_to "About Me", action: "about" %>
Try using the literal hash:
<%= link_to "About Me", {class: "changeMe", controller: "welcome", as: "AboutMe", action: "about"} %>
PS. Also, there is double l in controller. You have one.

Add CSS class to mail_to ruby on rails helper

I know that you can add HTML classes to link_to helpers like this:
<%= link_to 'Logout', logout_path, class: 'primary-link-style' %>
But what about the mail_to helper? There doesn't seem to be a way to add a HTML/CSS class like you can with the link_to helper.
The docs only talk about examples of inline styling which I want to avoid.
The method signature from the docs you linked to:
mail_to(email_address, name = nil, html_options = {}, &block)
That third argument, html_options, works just like the same argument of link_to:
<%= mail_to "foo#example.com", "Email me", class: "primary-link-style" %>

Cannot use html tags inside popover

I have the following code,my problem is when i tried to add or any other html tag inside it as shown its not working and it displayed as normal string.
<%= link_to image_tag(class_door(student_class), onMouseover: "this.src='/assets/open_door.png';", onMouseout: "this.src='/assets/closed_door.png'" ),'javascript:;' ,class:'popovers','data-content'=>"Number of Students: #{student_class.students.count}<br><button>Click to enter</button>" ,'data-original-title'=>"#{student_class.name.capitalize}" %>
also i have tried to add html_safe to be like this
<%= link_to image_tag(class_door(student_class), onMouseover: "this.src='/assets/open_door.png';", onMouseout: "this.src='/assets/closed_door.png'" ),'javascript:;' ,class:'popovers','data-content'=>"Number of Students: #{student_class.students.count}<br><button>Click to enter</button>".html_safe ,'data-original-title'=>"#{student_class.name.capitalize}" %>
but this also wasn't working and giving the same result
Try adding 'data-html'=>true. You'd want something like:
<%= link_to image_tag(class_door(student_class), onMouseover: "this.src='/assets/open_door.png';", onMouseout: "this.src='/assets/closed_door.png'" ),'javascript:;' ,class:'popovers', 'data-html'=>true, 'data-content'=>"Number of Students: #{student_class.students.count}<br><button>Click to enter</button>" ,'data-original-title'=>"#{student_class.name.capitalize}" %>
And if any of the values you are putting into your HTML need to be escaped to prevent injection, you can use "h". Something like: #{h(student_class.name.capitalize)}.

Very basic rails link_to issue

Hello all I have a Delete link that I'm trying to create with the following code:
<%= link_to 'Delete', element, method: :delete, data: { confirm: 'Are you sure?' } %>
However the resulting link is /element.id where the id is the integer id. How would I change that . to a / sorry I know this is very elementary but I couldn't find any documentation on it.
Try this
<%= link_to 'Delete', destroy_modelname_path(element), method: :delete, data: { confirm: 'Are you sure?' } %>
Replace modelname with the name of your model.
Run rake routes in terminal in your app to see all routes.
I guess the problem is in config/routes.rb, it should contain a reference to element, like:
resources :element
There is something wrong with routes file. It seems that your routing routine writes id in the place of :format.