Access the variables of view in controller

Hello frnds

I want to access the variables of view in my controller… What i want to
do is that the value that i m storing in view i want to store that thru
a variable by defining it in the controller…

is that possible?

Please reply

Thanks

On 7 Oct 2007, at 13:47, Dhaval P. wrote:

Hello frnds

I want to access the variables of view in my controller… What i
want to
do is that the value that i m storing in view i want to store that
thru
a variable by defining it in the controller…

That doesn’t really make sense since usually the rendering of the
view happens after the controller code has executed. Views magically
get instance variables defined in the controller, but that doesn’t
happen in the reverse direction.

Fred

hi thanks for ur reply i will tell you the whole situation and after
that u suggest me the best method…

say i have a table which i m generating some how…now i want to match
the email condition which i have done by using .match in view and
storing that in @email variable…like that i m fetching 2-3 things form
that table…which im storing in individual variables… now i want to
store the value of that variable into a new table in the appropriate
column…remember i m currently doing this in view which lead me to ask
you this question…

i know that the samething can be done in controller but then what about
the .match condition it doesnt work in the controller…and i m not
getting any other solution apart from doing this…i m getting the
desired result in my list page but those values i want to store in the
database…

can u pls guide me how can i do the same

thanks

dhaval parikh

On 8 Oct 2007, at 08:34, Dhaval P. wrote:

store the value of that variable into a new table in the appropriate
column…remember i m currently doing this in view which lead me to
ask
you this question…

This is still rather vague, but anyway the answer is ‘Stop doing too
much in the view’. Theres no good reason to do stuff like that in the
view.

Fred

wat you are saying is perfect but the main issue is that i dont find any
other way out for doing the same…i mean matching the email condition in
the controller

On 8 Oct 2007, at 09:34, Dhaval P. wrote:

wat you are saying is perfect but the main issue is that i dont
find any
other way out for doing the same…i mean matching the email
condition in
the controller

No one can guess what it is you’re doing without seing any code.

Fred

in the above code <% “insert into email(mail,subject,source) VALUES
(’@desc[:email]’,’@link[:source]’,’@title’[:subject])”; %> is used for
inserting th evalues into the db this is wat i m stuck with…how to do
it with the help of controller…

ofcourse the above code i m writing in views which i dont want to do

<% for aggregator_item in @aggregator_items %>

<% if @desc =
aggregator_item.send(“description”).match(/\S+@\S+.[a-zA-Z0-9]{1,}/) %>


<% @timestamp = aggregator_item.send(“timestamp”) %>

<%=h @link = aggregator_item.send(“link”) %>

<%=h @desc%>

<%=h @title = aggregator_item.send(“title”)%>

<%= Time.at(@timestamp) %>
<% “insert into email(mail,subject,source) VALUES
(’@desc[:email]’,’@link[:source]’,’@title’[:subject])”; %>


<% end %>
<% end %>

this is the code im using now the values of @desc,@link and @title i
want to put it into the database…now can you tell me wat can i do??

can you tell me how do i write the same thing in model/?

On 8 Oct 2007, at 10:11, Dhaval P. wrote:


<%=h @desc%>

You could very easily have all of this in a model. The model would
insert them into the database, (why are you using sql rather than the
corresponding ActiveRecord class?) and return an array of these
activerecord objects, which you would iterate over in the view.

Fred

On 8 Oct 2007, at 10:42, Dhaval P. wrote:

can you tell me how do i write the same thing in model/?

It’s pretty much what you’ve got in your view - iterate over your
aggregator objects, pull out the values you want and pass them to
Email.create

Fred

On 8 Oct 2007, at 11:40, Dhaval P. wrote:

same…
Don’t write sql. Do use activerecord. if you’re inserting to the
emails table then it’s just Email.create, passing the desired
attributes as a hash.

Fred

ya did that too but stuck with the insert query can you tell me the
exact query which i will use to insert records into the database…in
another table
(note i m fetching values from one table and I need to store that in
another table)

i will have to insert the value of variable @email into the specified
email column…but it would be gr8 if u tell me the exact syntex for the
same…