Ruby on rails form_tag - 将模型参数发送到控制器

use*_*922 2 ruby ajax ruby-on-rails ruby-on-rails-3

控制器: @micropost = Micropost.new(params[:micropost])

但是这个form_tag正在发送给我params[:content]而不是params[:micropost][:content]

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

    <%= text_area_tag :content, "", :size=> "20x2" %>
    ...
    ...
    ...
    <%= submit_tag "submit" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

服务器:

Processing by MicropostsController#create as JS
Parameters: {"utf8"=>"?", "content"=>"sdfsdf", "commit"=>"submit"}
Run Code Online (Sandbox Code Playgroud)

Sal*_*lil 9

您必须执行以下任一操作

<%= text_area_tag "micropost[content]", "", :size=> "20x2" %>
Run Code Online (Sandbox Code Playgroud)

要么

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