控制器:@micropost = Micropost.new(params[:micropost])
但是这个表单标签发送给我的是params[:content]而不是params[:micropost][:content]

<%= form_tag( {:controller => :microposts, :action => :create}, :remote => true) do %>

    <%= text_area_tag :content, "", :size=> "20x2" %>
    ...
    ...
    ...
    <%= submit_tag "submit" %>
<% end %>

服务器:
Processing by MicropostsController#create as JS
Parameters: {"utf8"=>"✓", "content"=>"sdfsdf", "commit"=>"submit"}

最佳答案

你必须做以下两件事之一

<%= text_area_tag "micropost[content]", "", :size=> "20x2" %>


<%= form_for :micropost, :url=>{ :controller => :microposts, :action => :create}, :remote => true do |f| %>
    <%= f.text_area :content, "", :size=> "20x2" %>
<% end %>

关于ruby-on-rails - Ruby on Rails form_tag-将模型参数发送到 Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12037286/

10-11 05:57