开发者

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=&gt;[:erb, :builder, :coffee], :formats=&gt;[:js, :html], :locale=&gt;[:en, :en]}. Searched in:
  * &quot;~/app_dir/app/views&quot;

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜