I am new in Ruby and Rails and little bit confused about rendering and adding routes for a new template.
I have following link_to
tag
<td colspan="3">
<%= link_to 'Show Current State', simulation, :action => :current_state, :class => 'btn btn-primary'%>
</td>
Where simulation
is the name of controller and action is name of the method in SimulationController
.
I added this in my routes.rb
resources :simulations, except: [:edit]
resources :simulations do
collection do
get 'current_state'
post 'current_state'
end
end
In my SimulationController
class I added a new method i.e.
def current_state
byebug
end
My problem? routes is not re-directing to current_state
method. Instead, it is redirecting to http://localhost:3000/simulations/{someID}
This redirection is calling show
action.
def show
...
end
How can I make this work out and make <%= @simulation.dat %>
line accessible in new.html.erb
. Location of new.html.erb
is in following path
views/simulations/index.html.js
views/similations/show.html.js
views/simulations/new.html.erb
This could be a basic question but I am new to rails 4. Thanks in advance.
Edit-1
Def of get_state
method in controller
def get_state
@simulation = current_user.simulations.find(params[:id])
return not_found if @simulation.nil?
.....
/// How to send `@simulation` into `state.html.erb` formally as `new.html.erb`
end