In my paintings controller, show action. I''ve got a comment form. How
should I pass the painting_id and user_id to the form?
Currently, my paintings controller looks like:
def show
@painting = Painting.find(params[:id])
@comment = Comment.new
....
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi,
If you have fields like painting_id and user_id in your Comment table
than you can do as follow.
def show
@painting = Painting.find(params[:id])
@comment = Comment.new
@comment.user_id = @painting.user_id # Or your desire value...
@comment.painting_id = @painting.id
end
Thanks
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-14 09:15 UTC
Re: How should one pass params to the comment form
That doesnt work.... the form is submitted but the values user_id and painting_id are not set in the db. Only the comment is saved On Oct 14, 4:46 pm, Smit Shah <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > If you have fields like painting_id and user_id in your Comment table > than you can do as follow. > > def show > @painting = Painting.find(params[:id]) > @comment = Comment.new > @comment.user_id = @painting.user_id # Or your desire value... > @comment.painting_id = @painting.id > end > > Thanks > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-14 09:43 UTC
Re: How should one pass params to the comment form
I think you mean:
@comment = Comment.new
@comment.user_id = @painting.user_id # Or your desire value...
@comment.painting_id = @painting.id
MUST be in the comment controller, create action. Not new or show
action....
On Oct 14, 5:15 pm, Christian Fazzini
<christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> That doesnt work.... the form is submitted but the values user_id and
> painting_id are not set in the db. Only the comment is saved
>
> On Oct 14, 4:46 pm, Smit Shah
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
>
> > Hi,
>
> > If you have fields like painting_id and user_id in your Comment table
> > than you can do as follow.
>
> > def show
> > @painting = Painting.find(params[:id])
> > @comment = Comment.new
> > @comment.user_id = @painting.user_id # Or your desire value...
> > @comment.painting_id = @painting.id
> > end
>
> > Thanks
>
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Oct-14 12:32 UTC
Re: Re: How should one pass params to the comment form
On Thu, Oct 14, 2010 at 5:43 AM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think you mean: > > @comment = Comment.new > @comment.user_id = @painting.user_id # Or your desire value... > @comment.painting_id = @painting.id > > MUST be in the comment controller, create action. Not new or show > action.... >yes it has to be in the create action of the comment controller and also you have to fetch the painting data so pass it in a hidden field on the form. @comment = Comment.new @comment.user_id = @painting.user_id # Or your desire value... @comment.painting_id = @painting.id -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini
2010-Oct-14 14:59 UTC
Re: How should one pass params to the comment form
Yeap, got it. Thanks for clearing that up Radhames On Oct 14, 8:32 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Oct 14, 2010 at 5:43 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I think you mean: > > > @comment = Comment.new > > -I4CJOCdi0N4BB6bauf/WkQ@public.gmane.org_id = @painting.user_id # Or your desire value... > > -I4CJOCdi0N65ScI7nuhTog@public.gmane.org_id = @painting.id > > > MUST be in the comment controller, create action. Not new or show > > action.... > > yes it has to be in the create action of the comment controller and also you > have to fetch the painting data so pass it in a hidden field on the form. > > @comment = Comment.new > > -I4CJOCdi0N4BB6bauf/WkQ@public.gmane.org_id = @painting.user_id # Or your desire value... > -I4CJOCdi0N65ScI7nuhTog@public.gmane.org_id = @painting.id-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.