On Fri, Mar 11, 2011 at 2:33 PM, Luke <[email protected]> wrote:

> Hi there,
>
> I posted this issue
> <https://groups.google.com/forum/?hl=de#!topic/carrierwave/ergk9LaO68k>at
> the carrierwave-group, but I'm beginning to think this rather is a
> rails-issue than a problem with carrierwave. The problem's this:
>
> I have 2 models, 'article' and 'upload'. article has_many :uploads. In my
> article_controller i have an action named upload:
>
> def upload
>   @article = Article.find(params[:id])
>   @article.uploads.create(params[:file])
>   render :nothing => true
> end
>
>
you forgot that you need to pass in key value pairs (as mentioned lower )

def upload
  @article = Article.find(params[:id])
  @article.uploads.create(:file => params[:file])
  render :nothing => true
end

There is nothing wrong with using create on uploads - it is added to the
collection when you use has many - it in the right way.

you could also do this whole thing in the update action for the article
controller if you simply use 'fields_for' inside of a form_for @article
and set 'accepts_nested_attributes_for :uploads'

then you could do the RESTful way.

def update
  @article = Article.find(params[:id])
  @article.update_attributes(params[:article])
end












-- 
make haste slowly \
festina lente  \
-
mobile  +1_415_632_6001
[email protected] <[email protected]>
http://robotarmyma.de

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to