Reputation: 81
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'.
Upvotes: 0
Views: 538
Reputation: 1504
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
Upvotes: 2