1

Hello right now I've a problem about button_to

I want to setup a button that call a method in controller, this is how I setup the button :

(this located in issues/_edit.html.erb)

<%= button_to "Cancel Return", :action => "cancel_return", :controller => "issues" %>

and I want this will call this function in issues_controller.rb

  def cancel_return
    @issue.cancel_return(params)
  end

I also added it in the routes.rb

map.issue_cancel_return 'issues/cancel_return', :controller => 'issues',
                       :action => 'cancel_return'

but it can't work, I already tried to declare cancel_return as helper_method, but it also didn't work. is there any other solution? or I'm doing it wrong? I'm using ruby version 1.9.3p125 and rails version 2.3.15, I used old version because I tried to modify redmine, any help will be appreciated.

Thanks

4
  • is issues#cancel_return a valid route? i haven't seen redmine's routes.rb but did you also the new action in there aside from adding it in the controller? Commented Aug 28, 2013 at 5:18
  • @roninblade actually I'm not actually sure how to put it in the routes.rb, I added it like this map.issue_cancel_return 'issues/cancel_return', :controller => 'issues', :action => 'cancel_return', you can also see it in the edited question Commented Aug 28, 2013 at 5:39
  • what happens when you call the action directly on your browser? ie. 127.0.0.1:3000/issues/cancel_return/?plus_your_extra_params Commented Aug 28, 2013 at 7:09
  • @roninblade error 403 not auothorized even I'm login to the site as admin Commented Aug 28, 2013 at 9:02

1 Answer 1

2

you should be putting them in a curly braces like this

<%= button_to "Cancel Return", { :controller => "issues", :action => "cancel_return"} %>

what happening is that map is not defining the method for the call like GET/POST/DELETE so what you can do is use this instead of you map line in your routes.rb file

get "issues/cancel_return" => "issues#cancel_return"

this should solve your problem.

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

6 Comments

still nothing happens :(, how can I know the function is called beside the database change? is there any method like php print_r("TEXT");exit; in RoR?just to make sure my button works
look at you server log, that what request is being happening and what is called and what not.
I guess it's not called the last 3 action showed in the log after I clicked the button is Processing IssuesController#show (for 172.16.20.1 at 2013-08-28 11:42:16) [GET] Parameters: {"controller"=>"issues", "action"=>"show", "id"=>"833"} Rendering template within layouts/base Rendering issues/show Completed in 408ms (View: 65, DB: 316) | 200 OK do you know why it's not called?
@nayoso can you please write the path that you have given in the routes.rb, show what poppes out with both show and cancel_return methods.
i meant do rake paths and tell me what method each action is showing you know like 'get/put/delete' types
|

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.