2

Controller: @micropost = Micropost.new(params[:micropost])

But this form_tag is sending me params[:content] instead of params[:micropost][:content]

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

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

server:

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

2 Answers 2

9
+50

You have to do either of the following

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

OR

<%= form_for :micropost, :url=>{ :controller => :microposts, :action => :create}, :remote => true do |f| %>
    <%= f.text_area :content, "", :size=> "20x2" %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

2

You have to avoid mixing form_for and input_tag.

When you declare a form_for @an_object do |form|, the best practice is to use form.text_area :content when :content is an attribute of your @an_object.

In this case, you can also write: text_area_tag "an_object[content]", but it's a little more dirty.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.