Presentation is loading. Please wait.

Presentation is loading. Please wait.

Section led by Ivan Lee Reachable at ivan period lee at cs period stanford period edu 1.

Similar presentations


Presentation on theme: "Section led by Ivan Lee Reachable at ivan period lee at cs period stanford period edu 1."— Presentation transcript:

1 Section led by Ivan Lee Reachable at ivan period lee at cs period stanford period edu 1

2 { :action => “train" } do |f| %> Name: 2

3 … 3

4 In your controller… Access using params[:ninjaTurtle][:name] Ex: If params[:ninjaTurtle][:name] == ‘turtle’ flash[:warning] = “Your turtle needs a better name!” # see how “flash” is displayed a few slides down end 4

5 {:action => :photoPost}, :html => { :multipart => true }) do |form| %> 5

6 6

7 You can treat it as a global variable session["login_id"] = user.id; If session["login_id"] == nil… Can store all sorts of fun stuff in the session But when you’re all done, clean up! reset_session 7

8 Usage if (dont_want_to_reload_page) render(:controller => turtles, :action => :attack) end Note: “:action” renders the view with the same name as the action 8

9 From the Rails book, pg. 397 Many forms require a user to enter some piece of information twice, the second copy acting as a confirmation that the first was not mistyped. If you use the naming convention that the second field has the name of the attribute with _confirmation appended, you can use validates_confirmation_of to check that the two fields have the same value. The second field need not be stored in the database. 9

10 Ex (if you really wanted to ensure the Ninja Turtle’s favorite color): class Turtle < ActiveRecord::Base validates_confirmation_of :color end 10

11 if (there_is_a_post_error) @errorMessage = “You can’t do that!” render(:action => previousAction) return end 11

12 To look something up in the database by multiple fields, use Model.find(:first, :conditions => { … } ) Write out a map of what redirects where Last part: basically don’t use self.method Def method NOT Def MyClass.method or def self.method Make your layouts prettier – this helps with frustration when debugging “but it still looks so nice!” 12

13 13


Download ppt "Section led by Ivan Lee Reachable at ivan period lee at cs period stanford period edu 1."

Similar presentations


Ads by Google