0

I was going to create a link to a controller's action update_heimdall here is the code:

app/controller/admins_controller:

  def heimdall
    @headline = "Heimdall"
    @users = User.where(deleted_at: nil)
    authorize @users
    @focusUser = params['users'].blank? ? current_user : User.find(params['users'])
    heim = Heimdall.new
    @cards = heim.get_cards(@focusUser.trello_id, @focusUser.trello_access_token, @focusUser.trello_secret_token)
  end

  def update_heimdall 
    @user = params['users'].blank? ? current_user : User.find(params['users'])
    authorize @user
    heim = Heimdall.new
    heim.update_cards(@user.trello_id, @user.trello_access_token, @user.trello_secret_token)
  end

app/views/admins/heimdall.html.rb:

<%= link_to "Odśwież", update_heimdall(), class: "btn btn-warning" %>

I am enclosing as well listing from rails routes command:

heimdall GET    /heimdall(.:format) admins#heimdall                                        
update_heimdall GET   /heimdall/update_heimdall/:id(.:format)   admins#update_heimdall               

Unfortunately this code causes the following error:

undefined method `update_heimdall'.

1 Answer 1

2

As in your code, convert heim in to an instance variable @heim so that you can access it in views. then call specifiy the object in action path.

When you performed rake routes you will get all the paths on left side

heimdall GET    /heimdall(.:format) admins#heimdall                                        
update_heimdall GET   /heimdall/update_heimdall/:id(.:format)   admins#update_heimdall               

therefore your code should be:

<%= link_to "Odśwież", update_heimdall_path(@heim), class: "btn btn-warning" %>

for more information you can checkout this ruby on rails guide: http://guides.rubyonrails.org/getting_started.html

Sign up to request clarification or add additional context in comments.

2 Comments

Also, the route requires an :id to be passed. Your code will still error out.
I got what was the problem. I didn't add _path at the end, my bad. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.