Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails [@parent,@son],:remote=>;是的,不需要JS_Ruby On Rails_Ajax_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails [@parent,@son],:remote=>;是的,不需要JS

Ruby on rails [@parent,@son],:remote=>;是的,不需要JS,ruby-on-rails,ajax,ruby-on-rails-3,Ruby On Rails,Ajax,Ruby On Rails 3,我有一张普通的旧表。该表单用于创建嵌套模型的新对象 #restaurant.rb has_many :courses #courses.rb belongs_to :restaurant #routes.rb resources :restaurants do resources :courses end 在我看来(在haml中),我有这样的代码: %li.course{'data-random'=>random} = form_for([restaurant,course],

我有一张普通的旧表。该表单用于创建嵌套模型的新对象

#restaurant.rb
has_many :courses
#courses.rb
belongs_to :restaurant
#routes.rb
resources :restaurants do
  resources :courses
end
在我看来(在haml中),我有这样的代码:

%li.course{'data-random'=>random}
  = form_for([restaurant,course], :remote=>true) do |f|
    .name= f.text_field :name, :placeholder=>'Name here'
    .cat= f.hidden_field :category
    .price= f.text_field :price,:placeholder=>'Price here'
    .save
      = hidden_field_tag :random,random
      = f.submit "Save"
我希望这个表单可以用JS(create.JS.erb)的action create of courses\u controller来回答,但是它像一个普通表单一样提交,并用html来回答

我做错了什么?这个问题类似于,但唯一的答案对我来说没有意义。 谢谢


在内部

您的控制器中是否有js format
format.js{render:layout=>false}
响应,并且您的创建视图应该是
create.js.rjs
(我说的是rails 3)

您可以发布相关的控制器代码吗?