Or is it better to create that @hash directly in the needed method,
like this:
def create
@hash = REXML::Document.new xmlfile
title123 = params[:title]
pub = @hash
params = {:watchedfamily => {:Prio_No => pub, :title =>
title123, :watchedmembers_attributes => pub}}
@watchedfamily = Watchedfamily.new(params[:watchedfamily])
end
Or put all the 'extract data from XML code' into a model and just call
the model where I need it?
The problem is that I don't know exactly what I should put in a model
and what in a controller.
Sebastian
On 28 Apr., 17:20, Sebastian <[email protected]> wrote:
> Yes you were right! I was definitely on the wrong track!
>
> The URL really helped to understand how to create nested active
> records.
>
> I still have a big problem. I have two methods in my controller SHOW
> and SAVE.
>
> In the show method I extract a lot of data from an XML into a hash
> variable. In the save method I want to store that variable in the
> database. The problem is that my @hash variable is only available in
> the first method.
> How can I access a variable from one method to another? Is session or
> flash a good idea for that, I don't need that data anymore after
> saving to db.
>
> Simplified methods look like this:
>
> class PatentController < ApplicationController
> def show #This method has more than 50 lines code in reality
> @hash = REXML::Document.new xmlfile
> end
>
> def create
> title123 = params[:title]
> pub = @hash
> params = {:watchedfamily => {:Prio_No => pub, :title =>
> title123, :watchedmembers_attributes => pub}}
> @watchedfamily = Watchedfamily.new(params[:watchedfamily])
> end
> end
>
> Cheers,
> Sebastian
>
> On 28 Apr., 12:28, Pale Horse <[email protected]> wrote:
>
>
>
>
>
>
>
> > > Sebastian wrote in post #995494:
>
> > > Thank you!
>
> > > I am still having the problem that the URI gets too large if I want to
> > > send to much data to the database. How can I avoid this?
>
> > What do you mean by 'the URI gets too large'? If you are running Rails
> > 3, I suggest you read more on nested form attributes when dealing with
> > active record objects:
>
> >http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/Clas...
>
> > --
> > 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 [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.