New to rails.This problem is most likely due to my misconception of how routing works but unsure. My little program is identical to the Articles blog example on the Ruby on Rails online beginners guide tutorial.
All I want to do is have a button/link in the show.html.erb file that would redirect me to another url, but I need to access the articles ID to access the url, in order to get the title from that article object.
in articles_controller.rb I have:
def join
@article = Article.find(params[:id]) --->getting error, cant find Article without ID
redirect_to(**irrelevant code**))
end
in show.html.erb I have:
<%= link_to "Click here", {method: 'get', :controller => "articles", :action => "join"}
in routes.db i have:
get '/articles/join', to: 'articles#join'
I am getting the error ActiveRecord::RecordNotFound in ArticlesController#join Couldn't find Article without an ID
Why doesn't this work for my join method? why is id from params[:id] only extractable in the other CRUD operations?
thanks
idfrom your html. How your join method could know what article you want to get ? So yourparams[:id]is null. Try to print it and you will see. - sonicget '/articles/:id/join', to: 'articles#join'which makes sure an id is required in the path itself. - 3limin4t0r