I have this bit of code in my email.controller user = @current_user story = @current_story recipient = story.user It doesn''t work because @current_story isn''t defined. How can I find the current page to make this work? -- 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.
On 29 June 2010 11:00, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have this bit of code in my email.controller > > user = @current_user > story = @current_story > recipient = story.user > > It doesn''t work because @current_story isn''t defined. How can I find the > current page to make this work?You haven''t given anywhere enough detail for us to help you. @current_story - what are you expecting this variable to contain? Saying "the current page" won''t help. Do you mean the current URL (@request.request_uri)? The current Page object (in which case you must have found the Page object using some code, assign that to @current_story. A variable from the session? @current_story = session[:current_story]. We need a lot more information to be able to help. @current_story is an instance variable, but there''s no information on what you''re expecting it to magically contain. Cheers, Andy -- 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.
Andy Jeffries wrote:> On 29 June 2010 11:00, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> I have this bit of code in my email.controller >> >> user = @current_user >> story = @current_story >> recipient = story.user >> >> It doesn''t work because @current_story isn''t defined. How can I find the >> current page to make this work? > > > You haven''t given anywhere enough detail for us to help you. > > @current_story - what are you expecting this variable to contain? > Saying > "the current page" won''t help. Do you mean the current URL > (@request.request_uri)? The current Page object (in which case you must > have found the Page object using some code, assign that to > @current_story. > A variable from the session? @current_story = session[:current_story]. > > We need a lot more information to be able to help. @current_story is an > instance variable, but there''s no information on what you''re expecting > it to > magically contain. > > Cheers, > > > AndyThe email is to be sent from a page containing a story and comments. I want it to go to @story.user''s email. If I use story= Story.find_by_id(2) it works but I want an expression to find the current story not one specified. Does that tell you enough? Do you want more files sent? Attachments: http://www.ruby-forum.com/attachment/4823/email_controller.rb -- 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.
Neil Bye wrote:> Andy Jeffries wrote: >> On 29 June 2010 11:00, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >>> I have this bit of code in my email.controller >>> >>> user = @current_user >>> story = @current_story >>> recipient = story.user >>> >>> It doesn''t work because @current_story isn''t defined. How can I find the >>> current page to make this work? >>Neil>> We need a lot more information to be able to help. @current_story is an >> instance variable, but there''s no information on what you''re expecting >> it to magically contain. >> >> Cheers, >> >> Andy > > The email is to be sent from a page containing a story and comments. I > want it to go to @story.user''s email. If I use story= > Story.find_by_id(2) it works but I want an expression to find the > current story not one specified. > Does that tell you enough? Do you want more files sent?Neil Does anybody know how to do this? I''ve googled loads and still can''t work it out Neil -- 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.
Neil Bye wrote:>> The email is to be sent from a page containing a story and comments. I >> want it to go to @story.user''s email. If I use story= >> Story.find_by_id(2) it works but I want an expression to find the >> current story not one specified. >> Does that tell you enough? Do you want more files sent?I assume you have a show page that contains the story and the comments. How are you triggering the email from that form? A hyperlink I assume? If that''s the case, just pass the current story id as a parameter on the link_to, which makes that id available in the controller for your Story.find(params[:id]) or something close to that. -- 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.
> Neil Bye wrote: >>> The email is to be sent from a page containing a story and comments. I >>> want it to go to @story.user''s email. If I use story= >>> Story.find_by_id(2) it works but I want an expression to find the >>> current story not one specified.Ar Chron wrote:>, just pass the current story id as a parameter on the > link_to, which makes that id available in the controller for your > Story.find(params[:id]) or something close to that.I now have <%= link_to "Email this user", :controller => "email", :action => "correspond", :id => @user.login, :story_id => @story.id %> In the email_controller.rb I have story = Story.find(params[:story_id]) Is that what you meant and why does it not work? -- 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.
On 30 June 2010 19:00, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> Neil Bye wrote: >>>> The email is to be sent from a page containing a story and comments. I >>>> want it to go to @story.user''s email. If I use story>>>> Story.find_by_id(2) it works but I want an expression to find the >>>> current story not one specified. > > Ar Chron wrote: >>, just pass the current story id as a parameter on the >> link_to, which makes that id available in the controller for your >> Story.find(params[:id]) or something close to that. > > I now have <%= link_to "Email this user", > :controller => "email", :action => "correspond", > :id => @user.login, :story_id => @story.id %> > > In the email_controller.rb I have > > story = Story.find(params[:story_id]) > > Is that what you meant and why does it not work?What is the value of params[:story_id]? Look in the log. Colin -- 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.
Colin Law wrote:> On 30 June 2010 19:00, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> I now have <%= link_to "Email this user", >> :controller => "email", :action => "correspond", >> :id => @user.login, :story_id �=> @story.id %> >> >> In the email_controller.rb I have >> >> story = Story.find(params[:story_id]) >> >> Is that what you meant and why does it not work? > > What is the value of params[:story_id]? Look in the log. > > ColinThis is the same problem as I posted in the Can''t find without id thread. You dont need to answer both This is all I have in the log: Processing EmailController#correspond (for 127.0.0.1 at 2010-06-30 19:32:58) [GET] [4;36;1mUser Load (0.5ms) [0m [0;1mSELECT * FROM "users" WHERE ("users"."id" = 1) LIMIT 1 [0m ActiveRecord::RecordNotFound (Couldn''t find Story without an ID): app/controllers/email_controller.rb:23:in `correspond'' Rendered rescues/_trace (57.5ms) Rendered rescues/_request_and_response (0.4ms) Rendering rescues/layout (not_found) I''ll look at the debugging section -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 June 2010 20:40, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 30 June 2010 19:00, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >>> I now have <%= link_to "Email this user", >>> :controller => "email", :action => "correspond", >>> :id => @user.login, :story_id �=> @story.id %> >>> >>> In the email_controller.rb I have >>> >>> story = Story.find(params[:story_id]) >>> >>> Is that what you meant and why does it not work? >> >> What is the value of params[:story_id]? Look in the log. >> >> Colin > This is the same problem as I posted in the Can''t find without id > thread. You dont need to answer bothYou should not ask the same question twice. So what is the value of @story.id? You could just display it on the page to find out if you do not know. The page with the link_to "Email this user" ... that is. Colin> > This is all I have in the log: > > Processing EmailController#correspond (for 127.0.0.1 at 2010-06-30 > 19:32:58) [GET] > [4;36;1mUser Load (0.5ms) [0m [0;1mSELECT * FROM "users" WHERE > ("users"."id" = 1) LIMIT 1 [0m > > ActiveRecord::RecordNotFound (Couldn''t find Story without an ID): > app/controllers/email_controller.rb:23:in `correspond'' > > Rendered rescues/_trace (57.5ms) > Rendered rescues/_request_and_response (0.4ms) > Rendering rescues/layout (not_found) > > I''ll look at the debugging section > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Colin Law wrote:> On 30 June 2010 20:40, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>>> You should not ask the same question twice.I wouldn''t have but the problem was so similar. So what is the value of> @story.id? You could just display it on the pageIt depends which story is shown, that''s my problem, it won''t pass as a parameter or some reason. -- 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.
On 30 June 2010 23:45, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 30 June 2010 20:40, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>>> > > >> You should not ask the same question twice. > > I wouldn''t have but the problem was so similar. > > So what is the value of >> @story.id? You could just display it on the page > > It depends which story is shown, that''s my problem, it won''t pass as a > parameter or some reason.Of course it depends which story is shown, it is the id of the individual story. If the value is nil then no parameter will be passed, if it is not nil then there should be a parameter. You can also look at the html of the page (view page source in browser) to check that the id is there in the href. Add code to show the id on the page and check that it also appears in the href. Colin -- 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.
Colin Law wrote:> On 30 June 2010 23:45, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> @story.id? �You could just display it on the page >>You can> also look at the html of the page (view page source in browser) to > check that the id is there in the href. > > Add code to show the id on the page and check that it also appears in > the href. > > ColinThis is from show.html.erb <%= @story.id %> <%= link_to "Email this user", :controller => "email", :action => "correspond" , :id => "@story_id" %> This is view source 2 <a href="/email/correspond/@story_id">Email this user</a> This is the error that results Couldn''t find Story with ID=@story_id Where am I going wrong -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 July 2010 09:41, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 30 June 2010 23:45, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> @story.id? �You could just display it on the page >>> > You can >> also look at the html of the page (view page source in browser) to >> check that the id is there in the href. >> >> Add code to show the id on the page and check that it also appears in >> the href. >> >> Colin > > This is from show.html.erb > > <%= @story.id %> > <%= link_to "Email this user", > :controller => "email", :action => "correspond" , :id => "@story_id"That is passing the string "@story_id" as the id, you want the value, so just :id => @story_id> %> > > This is view source > > 2 > <a href="/email/correspond/@story_id">Email this user</a> > > This is the error that results > > Couldn''t find Story with ID=@story_idYou should have been able to work it out from this, it is getting the string @story_id instead of 2 Colin> > Where am I going wrong-- 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.
> > You should have been able to work it out from this, it is getting the > string @story_id instead of 2 > > ColinHow can I make it take 2 without using @story.id to find it. If I move to story 3 it has to send 3. How does it know to do so? Sorry I just can''t get it. -- 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.
On 1 July 2010 10:01, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> >> >> You should have been able to work it out from this, it is getting the >> string @story_id instead of 2 >> >> Colin > > How can I make it take 2 without using @story.id to find it. If I move > to story 3 it has to send 3. How does it know to do so? Sorry I just > can''t get it.Read my previous email more carefully, and don''t snip so much that the thread cannot be followed without continuously referring to previous messages. I suggested that in the link_to it should be :id => @story_id which provides the value (2 in the case you showed), not :id => "@story_id" which provides a string "@story_id" I think you need to go through some basic ruby tutorials if that does not make sense. Colin -- 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.
> I suggested that in the link_to it should be > :id => @story_id > which provides the value (2 in the case you showed), not > :id => "@story_id" > which provides a string "@story_id" > > I think you need to go through some basic ruby tutorials if that does > not make sense. > > Colin<%= link_to "Email this user", :controller => "email", :action => "correspond" , :id => @story_id %> Gives exactly the same result -- 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.
Neil Bye wrote:> >> I suggested that in the link_to it should be >> :id => @story_id >> which provides the value (2 in the case you showed), not >> :id => "@story_id" >> which provides a string "@story_id" >> >> I think you need to go through some basic ruby tutorials if that does >> not make sense. >> >> Colin > > <%= link_to "Email this user", > :controller => "email", :action => "correspond" , :id => @story_id > %> > Gives exactly the same resultok @story.id Got it at last 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.