Rails 3: Difference between revisions

From Wiki
Jump to navigation Jump to search
Blanked the page
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Application Setup ==
* create project with
<pre>
rails new my_project
</pre>
* add gem dependencies to <code>Gemfile</code> at the root level
* update <code>config/application.rb</code> to load needed dependencies and update defaults
* double-check <code>/config/initializers</code> and <code>/config/environments</code>


Files in <code>lib/</code> are not automatically loaded, so you need to <code>require</code> them.
In <code>config/environments/development.rb</code>, set
<pre>
config.action_mailer.perform_deliveries = false
</pre>
No delivery attempt is performed, but you can still see the mail in the log file to check it looks good
== Other rails commands ==
<pre>
rails console
rails server
rails runner
</pre>
== Routing ==
Configured in <code>config/routes.rb</code>
<pre>
match 'products/:id' => 'products#show'
</pre>
The url <nowiki><code>http://localhost:3000/products/8</code></nowiki> will be mapped to the <code>show</code> action of the <code>products</code> controller with <code>params[:id]</code> set to 8
== Logging ==
Use these in models, views, controllers to send timestamped messages to the log.
<pre>
logger.debug "debug message"
logger.info "info message"
logger.warn "something bad"
logger.error "something broke"
logger.fatal "application dead"
</pre>

Latest revision as of 21:02, 28 June 2011