Q:

How to make a Controller Function call from Views Template in rails?

I am new to Rails and have a function in product_controller.rb
def detach
  @product.photo = nil
  @product.save
end

now I want to call this method from views file show.html.erb so the method get executed. How to do it ? I can see the 7 methods do get called through .find(params[id]) but that is also not clear to me. 

A:

Try changing as follow
<%= link_to 'detach_image', product_detach_path(@product) %>

I would suggest you to have a look at guides.rubyonrails.org/routing.html.
you can do as follow,
you can use match
match '/update_profile', :to => 'users#update_profile'

or
resources :users do
  get 'update_profile', on: :member
end

and then you would definitely have method in your users controller
def update_profile
  @user = User.find(params[:id])

  if @user.save
    redirect_to @user, notice: 'user updated successfully!'
  end
end

