Instead of the user entering a name, I want to pass their screen name
along with supplied :title and :content fields. here is what I've
got..
f.hidden_field :author, user.screen_name
here is the create method from Posts controller:
def create
@title = "Gravity"
@user = User.find(params[:id]) # this does not work, and I don't
know why
if request.post? and params[:post]
if new
flash[:notice] = "Comment created"
redirect_to :action => "index"
else
flash[:notice] = "Please complete all fields"
redirect_to :action => "create"
end
end
end
Instead of the user entering a name, I want to pass their screen name
along with supplied :title and :content fields. here is what I've
got..
f.hidden_field :author, user.screen_name
here is the create method from Posts controller:
def create
@title = "Gravity"
@user = User.find(params[:id]) # this does not work, and I don't
know why
if request.post? and params[:post]
if new
flash[:notice] = "Comment created"
redirect_to :action => "index"
else
flash[:notice] = "Please complete all fields"
redirect_to :action => "create"
end
end
end
Please help.
I would need more information but I'll try to guess, and since you are
using f.hidden_field you should have a form declaration related to a
particular object (let's say "comment"). In that case your author
information should be accessible through params[:comment][:author] in
your controller.
That means you should change the line
@user = User.find(params[:id])
in
@user = User.find_by_screen_name(params[:comment][:author])
Don't forget to change :comment by the good name. If not, then give us
more information.