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
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
No one can guess what it is you're doing without seing any code.
Fred
<% for aggregator_item in @aggregator_items %>
<% if @desc =
aggregator_item.send("description").match(/\S+@\S+\.[a-zA-Z0-9]
{1,}/) %>
<br /><% @timestamp = aggregator_item.send("timestamp") %>
<br /><%=h @link = aggregator_item.send("link") %>
<br /><%=h @desc%>
<br /><%=h @title = aggregator_item.send("title")%>
<br /><%= Time.at(@timestamp) %>
<% "insert into email(mail,subject,source) VALUES
('@desc[:email]','@link[:source]','@title'[:subject])"; %>
<br />
<% end %>
<% end %>
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
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
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