Can't Get Rails 3.1 to respond with js file correctly
I'm trying to make a form in Rails that will respond with a js file. Right now, I have a file in app/assets/javascripts/login.js.coffee.erb
that I'd like to be returned when the user submits the form via ajax (I've got users without javascript enabled working fine). Here's my template code for the form:
<%= form_tag("/trade/submit", :method => "post", :remote => true) do %>
# some stuff in here
<% end %>
In my trade controller, I have a method submit, which follows:
def submit
respond_to do |format|
format.html { render :layout => 'widget' + @widget_type.to_s, :template => 'login/index' }
format.开发者_开发技巧js { render :action => 'login', :content_type => 'text/javascript' }
end
end
My respond with html works fine, but when calling the form via ajax, it returns this response:
Missing template trade/submit, application/submit with {:handlers=>[:erb, :builder, :coffee], :formats=>[:js, :html], :locale=>[:en, :en]}. Searched in:
* "~/app_dir/app/views"
Obviously, it shouldn't be looking in views, but rather in javascripts, right? I tried removing the render block after format.js (keeping it default so it will look for submit), and I get the same problem. Does this mean I have to save my js files in my views directory? Seems kinda messy, so I feel like surely I must just be doing something wrong. Any help is greatly appreciated!
It tries to find app/view/trade/submit.js.erb! Try to do a simple test.
touch app/view/trade/submit.js.erb
vim app/view/trade/submit.js.erb
alert('done!');
And run it again.
精彩评论