Man, you missed the argument for the block. Primary error.
def my_action
And the point of Mr. Yoshiji is true. But your error was on the server side, has not yet reached the client side.
For style, I think that everything is fine if the js code is just one function call. If there is more JS code, it is better to display the js template
# controller format.js # app/views/my_controller/my_action.js.erb my_function();
Update : how to fix the dual rendering problem
You must have a returned #index if the condition is met, or the method will continue to execute and call rendering twice or more. Fix it like this:
def index @models = Model.all if current_user.name == "Bob" return my_action else # ...and some stuff respond_to do |format| format.html format.js #this is needed to handle ajaxified pagination end end
Billy chan
source share