I want to call a destroy action. It is already define in controller.
The model that I want to destroy is nested resource. But route is existing in rake routes result.
new_content_model GET /contents/:content_id/model/new(.:format) {:controller=>"models", :action=>"new"}
edit_content_model GET /contents/:content_id/model/:id/edit(.:format) {:controller=>"models", :action=>"edit"}
content_model PUT /contents/:content_id/model/:id(.:format) {:controller=>"models", :action=>"update"}
DELETE /contents/:content_id/model/:id(.:format) {:controller=>"models", :action=>"destroy"}
And I call destroy action from this url
<%= link_to "destroy nested model", content_model_path( #content.id, #model.id ), :confirm => "are you sure?", :method => :delete %>
It is no route matches.
Routing Error
No route matches "/contents/1/model/1"`
Please tell me some solutions.
Already wrote <%= javascript_include_tag :all %> in layouts/application.html.erb
Rails 3 link_to (:method => :delete) not working
I solved this problem.
It was wrong that I deleted rails.js and prototype.js.
Thank you for your attending. Sorry for lack of information.
Related
I have used link_to to call controller action.
<%= link_to "Inactive", {:controller => :leave_details, :action => :deactivate}, {:method => :post } %>.
but my requirement is to pass id also to controller action but when i try to pass id(:id=>leave_detail.id) it is not showing in params. my params look like
{"_method"=>"post", "authenticity_token"=>"3vfyGQ5V6GQXRt2aQt+DOT0b3eGgP7B401uclnIGLUU=", "action"=>"deactivate", "controller"=>"leave_details"}.
In route file i have added
resources :leave_details do
post :deactivate, :on => :collection
end
can anyone tell me what is going wrong in this code or what i am missing.
thnks
I've ran into a weird problem in Rails. When I try and submit a search query with the following form on my Uploads controller:
<%= form_tag ({:controller => "uploads", :action => 'find_uploads'}), :method => "get" do %>
<%=h text_field_tag :search, params[:search], :id => 'search_field' %>
<br />
<%= submit_tag "Search", :style=>"display:inline;" %>
<% end %>
I get redirected to the following url and error page:
/uploads/find_uploads?utf8=✓&search=bot&commit=Search
ActiveRecord::RecordNotFound in UploadsController#show
Couldn't find Upload with id=0
My find_uploads route: get 'uploads/find_uploads' => "uploads#find_uploads"
And when I did I rake routes this is what I got:
uploads_find_uploads GET /uploads/find_uploads(.:format) {:controller=>"uploads", :action=>"find_uploads"}
Everything seems to be in order... not sure why it's not working out as expected. For debugging purposes I dropped breakpoints in both my find_uploads and show actions and neither of them were reached so this error message must be lying to me as the UploadsController show action is never called!
This form is being rendered on my index page if it counts for anything.
I think it's taking find_uploads for an id.
Declare your routes like that:
resources :uploads do
collection do
get :find_uploads
end
end
ps: currently, when you do rake routes, /uploads/find_uploads is after /uploads/:id right?
I have the following when I do rake routes
next_post /users/next_post/:index(.:format) {:controller=>"users", :action=>"next_post"}
then, when I have this code in my ERB file:
<%= link_to "next", :next_post %>
I get the following error, and I just can't figure it out
No route matches {:controller=>"users", :action=>"next_post"}
What am I doing wrong here? The route itself looks like this
match '/users/next_post/:index',
:controller => "users",
:action => 'next_post',
:as => :next_post
You should use this
<%= link_to "next", next_post_path(#post.id + 1) %>
I am trying to use the vote_fu gem and I encounter a problem that other have as well, but I can't solve this with others' solutions..
I don't think the problem is related directly to the gem.. but rather to some wrong route or a missing parameter..
I have a Msg model which I included the act_as_voteable.
For the User Model I added act_as_voter
In the Msg controller I added
def votefor
#msg= Msg.find(params[:id])
current_user.vote_for(#msg)
redirect_to :back
end
In routes:
resources :msgs do
member do
post :votefor
end
end
And to the show of Msg I added
<%= link_to "Vote Up", votefor_msg_path(#msg), :method => :post %>
But when I click on the link created I get
Routing Error
No route matches [GET] "/msgs/1/votefor"
Why does it 'GET' instead of 'POST'? What am I missing?
I think its very late to answer this question & I mostly think you must have figured it out... I ran into the same issue & I understood the reason why..
This is a sample comment from routes.rb
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
the post 'toggle' here is not the post-controller but :method => 'post'
link_to default uses :method => 'get' but you can override it using :method => 'post'
if u use link_to .. in the example without :method => 'post'
your routing should be
resources :msgs do
member do
get :votefor
end
end
Hope this helps!
Update:
For the doubt you have:
link_to with a :method => :post
use this
<%= link_to "Vote Up", votefor_msg_path(#msg), :method => :post %>
and in the routes it should be
resources :msgs do
member do
post :votefor
end
end
the post :votefor .. is :method => :post not the posts controller.
Do check for brady8's answer
Why would this work?
<%= link_to "New Item", new_site_care_path, {:class => "button_bottom"} %>
And this (the only change is from link_to to button_to)...
<%= button_to "New Item", :url => new_site_care_path, {:class => "button_bottom"} %>
...produces:
No route matches "/site_cares/new"
UPDATE - ROUTE INFO -
route file:
resources :site_cares, :except => :show
rake routes:
new_site_care GET /site_cares/new(.:format) {:action=>"new", :controller=>"site_cares"}
I think that button_to uses post by default, my ROR route skills are a bit rusty but I think the route you've shown uses GET.
There's further info in this question - Button_to in Ruby on Rails bad route