I followed the steps indicated in this answer for setting up thumbs_up
https://stackoverflow.com/a/4963297/1643048
However I keep getting this error and have no idea how to fix it:
No route matches {:action=>"vote_up", :controller=>"posts", :id=>nil}
Can anyone help?
UPDATE:
exact error-
Routing Error
No route matches {:action=>"vote_up", :controller=>"posts", :id=>nil}
Try running rake routes for more information on available routes.
config/routes.rb:
Projectmadrone::Application.routes.draw do
devise_for :admins
#devise_for :users
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
resources :posts do
member do
post :vote_up
end
end
root :to => 'posts#index'
end
my view: app/views/posts/index.html.erb
<li><%= link_to('vote for this post!', vote_up_post_path(#post), :method => :post) %></li>
Your #post-variable seems to be nil. Propably because you are using it in the index-view instead of the show-view. So you should try to put the link_to-code into the app/views/posts/show.html.erb.
Related
I am missing the contacts#show prefix 'contact' as seen below.
rake routes
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
I am thinking this is the reason why I am getting a dot instead of a slash when clicking the following link.
_contact.html.erb
<%= link_to "delete contact", contact, method: :delete,
data: { confirm: "You sure?" } %>
The server logs the proper DELETE request, however, cannot render /contact.26 instead of the correct /contacts/26.
Started DELETE "/contact.26" for 128.177.12.30 at 2016-04-13 21:04:30 +0000
ActionController::RoutingError (No route matches [DELETE] "/contact.26"):
Every post I've come across with a dot instead of a slash seems to stem from a pluralization error, however, I don't believe this is the case here.
In addition, I've removed resources :contacts from my routes file, run $ rake routes, added resources :contacts, run $ rake routes, and the problem persists.
This problem seems to be unique to the contacts model, as the rest of my models aren't missing any prefixes or having this error when deleting.
How do I add the 'contact' prefix back to 'contacts#show'?
routes.rb file for reference:
Rails.application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
get 'newevent' => 'events#new'
get 'newteam' => 'teams#new'
get 'newperformance' => 'performances#new'
get 'newhotel' => 'hotels#new'
get 'newcontact' => 'contacts#new'
get 'newflight' => 'flights#new'
get 'newground' => 'grounds#new'
get 'newguest' => 'guests#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :users
resources :events
resources :teams do
member do
get :events
end
end
resources :performances
resources :hotels
resources :contacts
resources :flights
resources :grounds
resources :guests
resources :account_activations, only: [:edit]
resources :password_resets, only: [:new, :create, :edit, :update]
end
you may have a conflict between the routes set by
resources :contacts
and
get 'contact' => 'static_pages#contact'
The easiest solution is probably to change the static page's links. Best to keep the resources together if you can.
I just came across this same error.
the fix to my issue was that 's' at the end of resources
I had 'resource', and getting the same problem as you.
I changed it to 'resources' and it fixed my problem
in my case was just a typo.
This error showed up for me yesterday. What fixed it was deleting helper files that were not being used. Might be worth a try for you.
Problem which my terminal shows when I try rails server!
/home/<user_name>/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load': /home/salmanalam/rails_projects/blog/config/routes.rb:5: syntax error, unexpected ':', expecting keyword_end (SyntaxError)
post GET /posts/:id(.:format) posts#show
This is my content of config/routes.rb
Blog::Application.routes.draw do
resources :posts
get "welcome/index"
root 'welcome#index'
post GET '/posts/:id(.:format)' 'posts#show'
You have some extraneous (non)code at the conclusion of your routes. The entirety of your routes.rb should read something like this, instead:
# config/routes.rb
Blog::Application.routes.draw do
resources :posts
get "welcome/index"
root "welcome#index"
end
First, you're missing the end declaration to your block. Then, the piece of your code that reads post GET '/posts/:id(.:format)' 'posts#show' is not actually a route, but part of the output if you ran rake routes from the command line. It says that there's a show route for the Post resource.
I'm not sure how it got in your code, but removing it should resolve the issue you're having.
can you please try this
namespace 'posts', :defaults => {:format => 'eg.json'} do
match '/posts/event/:id', :to=> "post#show", :method => :get
end
root :to=>"welcome#index"
I'm trying to post to my registration controller using a link_to link.
I have <%= link_to "Register for Period", registration_path(period_id: period.id), :method => :post %>
Which generates a link like: http://localhost:3000/registrations/6?period_id=25 where the 6 is the event_id. I need to save the period_id and the user_id to the registration database.
I get the following error in the browser: No route matches [POST] "/registrations/6"
What am I doing wrong?
routes:
Mavens::Application.routes.draw do
devise_for :users
resources :events
resources :periods
resources :products
resources :cart_rows
resources :product_requests
resources :inqueries
resources :registrations
match '/profile', to: 'static_pages#profile'
root :to => 'static_pages#home'
get "static_pages/home"
get "static_pages/about"
end
If you put in your routes.rb:
resources :registrations do
member do
post :save_period
end
end
And in your link:
<%= link_to "Register for period",
save_period_registration_path(id: #registration.id, period_id: period.id), :method => :post %>
You will have a route that matches your resquest.
When you only have a resources :registrations rule on your routes.rb, only the default restful routes are created, and there is no POST to a single resource created by default.
I believe you will have to read something about the CSRF token, because if you have a protect_from_forgery on your application_controller, probably this POST request from a single link would not work.
Your routes.rb is missing the required path. It IS a standard path, so adding 'resources :registrations' would work.
If more complex, post your routes.rb and we can tell what to add.
I can't seem to correctly understand the routing in rails 3.1.
(keeping in mind I'm working on a project that depends on the refinery cms gem)
In my routes I have the following:
Blog::Application.routes.draw do
resources :news, :as => :news_items, :controller => :news_items, :only => [:show, :index]
scope :module => "refinery" do
scope(:path => 'refinery', :as => 'refinery_admin', :module => 'admin') do
resources :news, :as => :news_items, :controller => :news_items
#resources :news, :except => :show, :as => :news_items, :controller => :news_items
end
end
end
The output of the rake routes command is:
news_items GET /news(.:format) {:action=>"index", :controller=>"news_items"}
news_item GET /news/:id(.:format) {:action=>"show", :controller=>"news_items"}
refinery_admin_news_items GET /refinery/news(.:format) {:action=>"index", :controller=>"refinery/admin/news_items"}
POST /refinery/news(.:format) {:action=>"create", :controller=>"refinery/admin/news_items"}
new_refinery_admin_news_item GET /refinery/news/new(.:format) {:action=>"new", :controller=>"refinery/admin/news_items"}
edit_refinery_admin_news_item GET /refinery/news/:id/edit(.:format) {:action=>"edit", :controller=>"refinery/admin/news_items"}
refinery_admin_news_item GET /refinery/news/:id(.:format) {:action=>"show", :controller=>"refinery/admin/news_items"}
PUT /refinery/news/:id(.:format) {:action=>"update", :controller=>"refinery/admin/news_items"}
DELETE /refinery/news/:id(.:format) {:action=>"destroy", :controller=>"refinery/admin/news_items"}
The following code in my application leads to an error:
<%= form_for [:refinery, #news_item] do |f| %>
<% end %>
Telling me that the following path:
undefined method `refinery_news_items_path' for #<#<Class:0x0000010663c480>:0x00000106623980>
doesn't exist.
Any path from the rake routes command would just not work. I'm pretty confident that's it's a setting issue. I'm actually kind of writing a plugin to the RefineryCMS gem without actually using the plugin generator, I'm just building it as if it was a normal web app.
My project is hosted here for those who care to take a peak. http://github.com/mabounassif/blog
Anyone knows what might be the problem?
You're scoping your "refinery" scope as "refinery_admin" so when you did your rake routes, you got refinery_admin_news_items
if you take out that :as => 'refinery_admin' clause, your routes will return back to "normal"
It seems that the problem was with the way the Refinery CMS gem works. Apparently I shouldn't use the url helper right away, I should use the following instead:
main_app.new_refinery_admin_news_item_path
What is the equivalent index path for resources :topics if I were to write it out manually?
When I run rake routes with the resources line in the routes.rb file it shows.
GET /topics(.:format) {:action=>"index", :controller=>"topics"}
I have tried a few things with no success, for example:
get 'topics/index' #=> 'topics#index'
as the route says:
get "/topics" => "topics#index", :as => :topics
you can now use topics_path or topics_url