Rails button_to with image and actions -


i want show button image. have code

<%= image_submit_tag "down.png", controller: "posts", action: "votedown", post_id: post.id, topic_id: post.topic_id, class: "xta" %> 

its visible not calling action "votedown"

in routes have

post '/votedown', to: 'posts#votedown 

please suggest if there other way call method votedown params , image "down.png"

image_submit_tag must used in conjunction form - works normal html <input type="submit"> button.

you might want change route definition more restful:

patch '/posts/:id/votedown' => "posts#votedown", as: 'votedown_post' 

this makes more apparent route acts on post - , use patch method since changing resource instead of creating new resource.

armed our new route can create form:

<%= form_for(@post, url: votedown_post_path(@post) ) |f| %>   <%= image_submit_tag "down.png", class: "xta" %> <% end %> 

note not need add input post id since available params[:id].

another way use rails unobstructive javascript driver create link or button sends patch request '/posts/:id/votedown'.

<%= link_to image_tag("down.png", class: "xta"), votedown_post_path(@post), method: :patch %> 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -