I''m new with ROR and am confused about passing parameters to functions. I have a controller called Schedules and that calles a calendar helper for a view called show_cal.rhtml. I need to be able to pass in a specified month and year to get the correct schedule calendar to display in the view. I''m just starting with this and am simply trying to display the parameters I''m trying to pass in. Here''s what I''ve got so far: Controller: class SchedulesController < ApplicationController def index show_cal(yr, mo) render :action => ''show_cal'' end #...other functions not listed def show_cal(yr, mo) # set up dates based on yr, and mo end end View: show_cal.rhtml <h2>Calendar</h2> <%= yr %> <%= mo %> <%= link_to ''previous month'', :url => <h2>Calendar</h2> <%= yr %> <%= mo %> <%= link_to ''previous month'', :url => ''/schedules/show_cal?yr=2006&mo=5'' %> I know that this doesn''t work, but I''m trying to figure out how to get mo and yr to display, and how to pass them into the show_cal function from my link_to. I hope this makes sense. Any ideas? Thanks Dave -- Posted via http://www.ruby-forum.com/.
Welcome to Rails! Before you get too far, you need to get yourself used to doing things ''the rails way''. If you haven''t done the ''depot'' application in the Agile Web Development book, you should really do that. To fix your problem, we''ll use the link_to using parameters rather than a url. <%= link_to ''previous month'', :controller=>"schedules", :action => "show_cal", :yr=@previous_year, :mo =>@previous_month %> Retrieve values using params[] <%=params[:yr] %> <%=params[:mo] %> Now, in your controller, you''ll need to do some logic to determine what the previous and next month''s dates will be so you can make them available. def show_cal @previous_month = find_previous_month params[:mo] @next_month = find_next_month params[:mo] # the rest of your code end Hope that helps a bit. If not, let me know. Good luck! On 6/30/06, Dave Pancost <dave@powertolive.net> wrote:> > I''m new with ROR and am confused about passing parameters to functions. > I have a controller called Schedules and that calles a calendar helper > for a view called show_cal.rhtml. I need to be able to pass in a > specified month and year to get the correct schedule calendar to display > in the view. I''m just starting with this and am simply trying to > display the parameters I''m trying to pass in. Here''s what I''ve got so > far: > > Controller: > > class SchedulesController < ApplicationController > > def index > show_cal(yr, mo) > render :action => ''show_cal'' > end > > #...other functions not listed > > def show_cal(yr, mo) > # set up dates based on yr, and mo > end > > end > > View: show_cal.rhtml > > <h2>Calendar</h2> > <%= yr %> > <%= mo %> > > <%= link_to ''previous month'', :url => <h2>Calendar</h2> > <%= yr %> > <%= mo %> > > <%= link_to ''previous month'', :url => ''/schedules/show_cal?yr=2006&mo=5'' > %> > > I know that this doesn''t work, but I''m trying to figure out how to get > mo and yr to display, and how to pass them into the show_cal function > from my link_to. > > I hope this makes sense. > > Any ideas? > > Thanks > > Dave > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060630/54ec4e89/attachment.html
Hi, Brian, Thank you, thank you, thank you, thank you. What you gave me was just what I needed. You unlocked a mental block I just couldn''t seem to get through. I wasn''t getting that you can pass multiple parameters and name them what you need to name them. Most of the parameters passed in the depot application were simple :id parameters and I just had a brain dead moment by not putting it all together. Boy, do I feel dumb :-) Brian Hogan wrote:> Welcome to Rails! > > Before you get too far, you need to get yourself used to doing things > ''the > rails way''. If you haven''t done the ''depot'' application in the Agile Web > Development book, you should really do that.Thanks for the welcome. I really love ROR, there''s just some adjusting I need to make to my thinking as I progress. Unfortunately, because of circumstances beyond my control, I had to jump in to the deep end, but for me that''s the quickest way to learn. Anyway, thanks again for the assistance. I truly appreciate it. Dave -- Posted via http://www.ruby-forum.com/.
No problem at all. Good luck! On 6/30/06, Dave Pancost <dave@powertolive.net> wrote:> > Hi, Brian, > > Thank you, thank you, thank you, thank you. What you gave me was just > what I needed. You unlocked a mental block I just couldn''t seem to get > through. I wasn''t getting that you can pass multiple parameters and > name them what you need to name them. Most of the parameters passed in > the depot application were simple :id parameters and I just had a brain > dead moment by not putting it all together. Boy, do I feel dumb :-) > > Brian Hogan wrote: > > Welcome to Rails! > > > > Before you get too far, you need to get yourself used to doing things > > ''the > > rails way''. If you haven''t done the ''depot'' application in the Agile Web > > Development book, you should really do that. > > Thanks for the welcome. I really love ROR, there''s just some adjusting > I need to make to my thinking as I progress. Unfortunately, because of > circumstances beyond my control, I had to jump in to the deep end, but > for me that''s the quickest way to learn. > > Anyway, thanks again for the assistance. I truly appreciate it. > > Dave > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060630/4e0b2021/attachment.html