I'm getting the error in the title. I am not sure how exactly to write the routes, controller, and index.
I am trying to create a 'Refresh' button in an index.html.erb
view shown below:
...
<td><%= link_to 'Refresh', refreshProfile_affinity_path(a), method: :put %></td>
...
It is using this route in routes.rb
:
resources :affinities
put 'affinities/refreshProfile/:id' => 'affinities#refreshProfile'
It is trying to access the following method in the affinities_controller.erb
:
...
def refreshProfile
@affinity = Affinity.find(params[:id])
new_profile_affinity = User.find(@affinity.user_A_id).profile_affinity_with(User.find(@affinity.user_B_id))
if @affinity.update_attributes(:integer, new_profile_affinity)
redirect_to @affinity
end
end
...
What could be wrong? Any help is greatly appreciated!
You need to add an as:
to your route, this is what specifies the prefix for the helper method and is why you're currently getting an undefined method error e.g.
put 'affinities/refreshProfile/:id' => 'affinities#refreshProfile',
as: 'refreshProfile_affinity'
refreshProfile_affinity_path
would then work, or you could give it a shorter, snappier name e.g. as: 'refreshProfile'
and then use refreshProfile_path
.