Fernando Maymone
Fernando Maymone

Reputation: 355

Button not calling a controller in ruby

I have a screen where a user can select differente kinds of plans for his account. Like this:

#plans
 <% Plan.all.order(:amount).each do |plan| %>
     <%= render 'shared/plan_detail', {plan: plan, button_text: 'Choose this' } %>
 <% end %>

 #plan_detail
 <div class="plan-details">
    <header class= <%= plan.css %> >
      <h3><%= plan.name %></h3>
      <small><%= plan.visibility %></small>      
      <p><%= plan.card_description.html_safe %></p>
      <span class="plan-price"><sup>$</sup><%= plan.amount.to_s %></span>
    </header>
    <article>
     <%= plan.features_description.html_safe %>
      <%= link_to button_text,  {:controller => "accounts", :action => "update_plan", :plan => plan.id }, title: button_text, :class=>"btn btn-md btn-block btn-outline-green dialog-open" %>
    </article>
 </div><!-- end plan details -->

And In my controller i have:

#accounts_controller.rb
def update_plan
  @plan = Plan.find(params[:plan])
  current_user.plan = @plan
  current_user.save
end

My routes its like this

  get '/account/plans', to: 'accounts#plans', as: :update_plan
  put '/account/plans', to: 'accounts#update_plan'

But I click on the button, and nothing happens. What Im doing wrong here?

Upvotes: 0

Views: 41

Answers (1)

Marcin Kołodziej
Marcin Kołodziej

Reputation: 5313

This is a long shot, but seeing that your link has dialog-open I wouldn't be surprised if there was some Javascript preventing your link from working. In order to debug this further I would

a) Check browser's Javascript console for any errors

b) Remove the dialog-open class to see what happens

Upvotes: 1

Related Questions