In my application, I am trying to create a link that will allow users to submit project proposals. When users are ready to submit it for review, users will click the link, which causes the boolean "submitreview" to be marked as true.
I followed this post as a guide: Rails 3 how do I use link_to to change the value of a boolean in the db?.
Right now, the boolean does NOT change from false to true and it also gets redirected to the following URL: http://localhost:3000/projects?submitreview=false
Any help would be appreciated, thanks!
* UPDATE * I have updated the code below as per suggestions, and have gotten it to update the boolean successfully after I click the link. It should be noted that this "form" that contains the link is also rendered on the new project forms. So my problem now is that when I click to new projects <%= link_to 'Start your project', new_project_path %>
, I get the following new error below. When I delete the link_to submitreview in the form, no error comes up and the new_project renders great. My guess is that the new_project has not created an ID for the project yet which there's a call in def submitreview
. Can this be resolved?
Routing Error
No route matches {:action=>"submitreview", :controller=>"projects", :id=># ... }
projects/_form.html.erb
<%= link_to "Submit Proposal", submitreview_project_path(@project), method: :put, class: "btn btn-primary" %>
projects_controller.rb
def submitreview
@project = Project.find(params[:id])
@project.update_attributes(submitreview: true)
redirect_to project_path(@project)
end
routes.rb
resources :projects do
member do
get :submitreview
put :submitreview
end
end
rake routes
submitreview_project GET /projects/:id/submitreview(.:format) projects#submitreview
PUT /projects/:id/submitreview(.:format) projects#submitreview
true
seems more appropriate. – giorgiantrue
with no quotes, but the link still does not update the boolean to true. – spl