1

So this is my controller function.

def fb_close
 current_user.update_user_points(SHARE_POINT_ONE, message, current_user.id, 0) if params[:post_id].present?
 respond_to do |format|
 format.js { render :js => "my_function();" }
 end
end

and im trying to go back a js function called my_function inside script tag on the same page. I'm getting an error like ActionController::UnknownFormat

I want to know where i was wrong. Please correct me.

I have a file named fb_close.html.erb i can get the call to that file.. Is there any way i can link it with a js function

asked Jun 4, 2014 at 8:55
5
  • From where and how are you calling fb_close action? What is the URL? Commented Jun 4, 2014 at 8:57
  • You should be better putting the code of my_function in a separate file of format js and call it like format.js { render 'your_file_name' } Commented Jun 4, 2014 at 8:59
  • Wold not be simpler to just create a fb_close.js.erb view and call there my_function(); ??? Commented Jun 4, 2014 at 8:59
  • @Octopus-Paul yea i did that..still im experiencing the same error Commented Jun 4, 2014 at 9:02
  • can you let us know what is the url you are trying to call as you have to call your action with .js postfix like so localhost:3000/controller/action.js Commented Jun 4, 2014 at 9:15

1 Answer 1

2

You should be better putting the code of my_function in a separate file of format js and call it like format.js { render 'your_file_name' }

respond_to do |format|
 format.js { render 'your_file_name' }
end

You have to create a file like fb_close.js.erb and put the code of my_function in it and call it like this

respond_to do |format|
format.js { render 'fb_close' }
end
answered Jun 4, 2014 at 9:12
Sign up to request clarification or add additional context in comments.

6 Comments

@NidhinSG What is the file name you created?
i got fb_close.html.erb file inside which i have placed a code like <% p"------" %> it was shown in terminal.. Is there any way i can load a script file inside that page then?
@NidhinSG Where do you have the code of my_fucntion? Try moving the code of my_function to separate file like fb_close.js.erb and call it as like this.
I told u there is no call going to that function.. im getting an eror..ActionController::UnknownFormat I did like what you said
@NidhinSG What are you trying to do? I you want call the function my_function,do as i said or if you want render just html file,change it to format.html { render 'fb_close' } and file name should be just fb_close.html.erb.
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.