There is a method has_edit_right? defined in customers_helper.rb file. The method needs to be accessed by both the controller and its view. The rspec returns NoMethodError:
1) CustomersController GET customer page 'edit' should be successful if current user is the owner of the customer
Failure/Error: post 'edit', :id => customer.id, :customer => {:name => "name changed"}
NoMethodError:
undefined method `has_edit_right?' for #<CustomersController:0x3df6980>
# ./app/controllers/customers_controller.rb:40:in `edit'
# ./spec/controllers/customers_controller_spec.rb:87:in `block (3 levels) in <top (required)>'
Any thoughts about the problem? Thanks.
Helpers are for views, that’s their point. They aren’t supposed to be available in the controller, they’re specifically for distilling out reusable view logic. If you need a method available to both the controller and its views, define a
protectedmethod in the controller and provide it to the view viahelper_method.In this example, the method
has_edit_right?defined in the controller will also be available to the views.