I'm having a lot of problems getting this to work, I don't quite understand how the view sends info to controller, so it can be manipulated.
I have a button, which when clicked should change its value. Values changes between Yes / No. When the button is clicked it needs to change the corresponding value in the database, then in the view I already have the logic that decides button value.
Here's some code, how I imagine it working...
show.html.erb view
<% status = @problem.status? 'No' : 'Yes' %>
<%= link_to status, @problem, :class => 'btn btn-success' %>
In my ProblemsController
def show
@problem = Problem.find(params[:id])
@problem.status ? @problem.status : (@problem.status == 'false')
end
def solve
end
I'm not sure if I should change the database value in show method or create another one. The problem is that I don't know how to communicate from the view to the controller. How can I do this?
I was considering adding :data { solve: @problem.status } to link_to tag, not sure if that would help though. So far I'm unable to enter solve method (I tried adding :action => 'solve' or :action => '/problems/solve' ), which didn't help. The following is something I just tried, but it doesn't work (doesn't go to solve action in ProblemsController).
<%= link_to status, @problem, :controller => 'problems', :action => 'solve', :class => 'btn' %>
I would definitely appreciate some help! Any ideas?
Edit: Added code for params in controller, which I had. Sorry I should've included it.