I don't know the details of your app but it looks like you need to pass
in the post id, the user id, and the (text) body of the comment --
something like:
or words to that effect. (It's very unlikely that you really should be
passing a value for the id field; that's generally handled
automatically with an integer value.)
It might be helpful to try out some comment creation in the application
console and make sure you understand what the create method expects and
what results you get. The console is a great learning and exploring
tool.
You have to show us the code in your view that has the form to make a
comment.
From your description, params[:body] is obviously not being set to
anything because you don't have a textarea or input box with the name
"body". If the name of the textarea or input is named "comment[body]"
then to access this value it would be params[:comment][:body].
Also if you have an association between users and comments, such as user
has_many :comments, you can just do
<%= form_tag :action => "comment", :id => @blogpost %>
<%= text_area "comment", "body", :cols => 40, :rows => 6 %><br />
<%= submit_tag "Comment" %>
I tried - @blogcomment = @user.blogcomments.create(:id =>
params[:body]) but this still remains a null value...
With "text_area :comment, :body, ..." you should use this
"params[:comment][:body]" instead. Which is what Kenneth said:
Kenneth wrote:
From your description, params[:body] is obviously not being set to
anything because you don't have a textarea or input box with the name
"body". If the name of the textarea or input is named "comment[body]"
then to access this value it would be params[:comment][:body].
Also as someone in the thread mentioned you probably shouldn't be
setting :id because the database will assign a unique one for you.
Instead you should be setting the relation id. Without seeing the
code it is difficult but I would guess something like this:
Or as suggested already use the association. Which is probably the
best way. Without seeing the code it is difficult but I would guess
something like this: