Riding the Rails
testing, vistas, RJS, plugins y gems
ActionView




        ActionPack + ActionController




                ActiveRecord




MySQL   MSSql      Oracle      M...
class UsersController < ApplicationController

 def index

 end

 def show

 end

 def new

 end

 def create

 end

 def ...
app/views/issues/index.html.erb
redirect
def filter
 redirect_to root_path
end


  http://localhost:3000/
def filter
   redirect_to @issue
  end


http://localhost:3000/issues/3
def filter
 redirect_to :back
end


http://localhost:3000/...
def filter
 redirect_to :back, :status => 301
end



   http://localhost:3000/...
render
def filter

        end



app/views/issues/ lter.html.erb
render :action => “ lter”
       render “ lter”
render :partial =>



           def filter
            render “index”
           end



 app/views/issues/index.html.erb
render :template =>



       def users
        render “users/index”
       end


  app/views/users/index.html.erb
render : le =>


 def bad_users
   render “/var/www/other_app/app/
views/users/index”
 end

  app/views/users/index.html.e...
render :text =>



def updated?
 render :text => “Done”
end
render :xml =>



def current
 render :xml => @issues
end
render :json =>



def current
 render :json => @issues
end
render :js =>



def add_issue
 render :js => “$(‘#products’).append(‘Done!’);”
end
helpers




imaginen que la foto tiene algo
que ver; me pareció genial
<head>
<title>Issue Tracker v0.1</title>
</head>
<%= stylesheet_link_tag "style" %>
<%= stylesheet_link_tag “reset”,
                      “style”,
                      “form”
              %>
<%= stylesheet_link_tag “reset”,
                      “style”,
                      “form”,
                     :cache ...
<%= stylesheet_link_tag “reset”,
                      “style”,
                      “form”,
                     :cache ...
<%= javascript_include_tag "application" %>
<%= javascript_include_tag :all %>
<%= javascript_include_tag :all,
                :recursive => true %>
<%= auto_discovery_link_tag(:rss,
            {:controller=>”issues”,
            :action => "feed"},
             {:title...
helpers
en el body
<%= image_tag “logo.png” %>
<%= image_tag “logo.png”,
       :size=>”15x15” %>
<%= image_tag “logo.png”,
       :size=>”15x15”,
            :mouseover=>”logo_alt.png” %>
content_for
<%= render :partial => “archivo” %>




_archivo.html.erb
<%= render :partial => “issues/fields” %>




issues/_fields.html.erb
<%= render :partial => “archivo”,
          :locals=> { :f => @form } %>




_archivo.html.erb
<%= render :partial => “archivo”,
            :object => @issue %>




_archivo.html.erb
<%= render :partial => “issue”,
            :collection => @issues %>




_issue.html.erb
<tr>
 <td><%=h issue.title %></t...
<%= render :partial => “issue”,
            :collection => @issues,
            :as => “item” %>




_issue.html.erb
<tr>
...
<%= render :partial => “issue”,
            :collection => @issues %>




_issue.html.erb
<tr>
 <td><%= issue_counter %></...
<%= render :partial => “issue”,
            :collection => @issues,
            :spacer_template => “spacer” %>




_space...
demo time
rss
respond_to do |format|
   format.html
   format.atom
 end
index.atom.builder
atom_feed do |feed|
 feed.title "Incidencias"
 feed.updated(@issues.last.updated_at)

 @issues.each do ...
RJS
respond_to do |format|

 format.js do


     render :update do |page|
          page.replace "issues", :partial=>"posts”
 ...
respond_to do |format|

 format.js do


  render :update do |page|
          page.insert_html :top, "issues",
            ...
respond_to do |format|

 format.js do


     render :update do |page|
          page.visual_effect :highlight “issues”
    ...
respond_to do |format|

 format.js do


     render :update do |page|
          page.toggle “issues”
     end


  end
end
respond_to do |format|

 format.js do


     render :update do |page|
          page.hide “issues”
     end


  end
end
respond_to do |format|

 format.js do


     render :update do |page|
          page[‘issues’]
     end


  end
end
respond_to do |format|

 format.js do


     render :update do |page|
          page[‘issues’].hide
     end


  end
end
respond_to do |format|

 format.js do


     render :update do |page|
          page.alert(“Huye!”)
     end


  end
end
respond_to do |format|

 format.js do


     render :update do |page|
          page << “doSomethingReallyCool();”
     en...
demo
RR01-07 Introducción a Ruby y Rails
RR01-07 Introducción a Ruby y Rails
Upcoming SlideShare
Loading in …5
×

RR01-07 Introducción a Ruby y Rails

1,116 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,116
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide


























































  • RR01-07 Introducción a Ruby y Rails

    1. 1. Riding the Rails testing, vistas, RJS, plugins y gems
    2. 2. ActionView ActionPack + ActionController ActiveRecord MySQL MSSql Oracle MongoDB API
    3. 3. class UsersController < ApplicationController def index end def show end def new end def create end def edit end def edit end def destroy end end
    4. 4. app/views/issues/index.html.erb
    5. 5. redirect
    6. 6. def filter redirect_to root_path end http://localhost:3000/
    7. 7. def filter redirect_to @issue end http://localhost:3000/issues/3
    8. 8. def filter redirect_to :back end http://localhost:3000/...
    9. 9. def filter redirect_to :back, :status => 301 end http://localhost:3000/...
    10. 10. render
    11. 11. def filter end app/views/issues/ lter.html.erb
    12. 12. render :action => “ lter” render “ lter”
    13. 13. render :partial => def filter render “index” end app/views/issues/index.html.erb
    14. 14. render :template => def users render “users/index” end app/views/users/index.html.erb
    15. 15. render : le => def bad_users render “/var/www/other_app/app/ views/users/index” end app/views/users/index.html.erb
    16. 16. render :text => def updated? render :text => “Done” end
    17. 17. render :xml => def current render :xml => @issues end
    18. 18. render :json => def current render :json => @issues end
    19. 19. render :js => def add_issue render :js => “$(‘#products’).append(‘Done!’);” end
    20. 20. helpers imaginen que la foto tiene algo que ver; me pareció genial
    21. 21. <head> <title>Issue Tracker v0.1</title> </head>
    22. 22. <%= stylesheet_link_tag "style" %>
    23. 23. <%= stylesheet_link_tag “reset”, “style”, “form” %>
    24. 24. <%= stylesheet_link_tag “reset”, “style”, “form”, :cache => true %>
    25. 25. <%= stylesheet_link_tag “reset”, “style”, “form”, :cache => “styles” %>
    26. 26. <%= javascript_include_tag "application" %>
    27. 27. <%= javascript_include_tag :all %>
    28. 28. <%= javascript_include_tag :all, :recursive => true %>
    29. 29. <%= auto_discovery_link_tag(:rss, {:controller=>”issues”, :action => "feed"}, {:title => "Incidencias"}) %>
    30. 30. helpers en el body
    31. 31. <%= image_tag “logo.png” %>
    32. 32. <%= image_tag “logo.png”, :size=>”15x15” %>
    33. 33. <%= image_tag “logo.png”, :size=>”15x15”, :mouseover=>”logo_alt.png” %>
    34. 34. content_for
    35. 35. <%= render :partial => “archivo” %> _archivo.html.erb
    36. 36. <%= render :partial => “issues/fields” %> issues/_fields.html.erb
    37. 37. <%= render :partial => “archivo”, :locals=> { :f => @form } %> _archivo.html.erb
    38. 38. <%= render :partial => “archivo”, :object => @issue %> _archivo.html.erb
    39. 39. <%= render :partial => “issue”, :collection => @issues %> _issue.html.erb <tr> <td><%=h issue.title %></td> <td><%=h issue.code %></td> <td><%=h issue.description %></td> </tr>
    40. 40. <%= render :partial => “issue”, :collection => @issues, :as => “item” %> _issue.html.erb <tr> <td><%=h item.title %></td> <td><%=h item.code %></td> <td><%=h item.description %></td> </tr>
    41. 41. <%= render :partial => “issue”, :collection => @issues %> _issue.html.erb <tr> <td><%= issue_counter %></td> <td><%=h issue.title %></td> <td><%=h issue.code %></td> <td><%=h issue.description %></td> </tr>
    42. 42. <%= render :partial => “issue”, :collection => @issues, :spacer_template => “spacer” %> _spacer.html.erb <div style=”clear:both;”/>
    43. 43. demo time rss
    44. 44. respond_to do |format| format.html format.atom end
    45. 45. index.atom.builder atom_feed do |feed| feed.title "Incidencias" feed.updated(@issues.last.updated_at) @issues.each do |issue| feed.entry(issue,:url=>issue_path(issue)) do |entry| entry.title(issue.title) entry.content( issue.description, :type=>'html') end end end
    46. 46. RJS
    47. 47. respond_to do |format| format.js do render :update do |page| page.replace "issues", :partial=>"posts” end end end
    48. 48. respond_to do |format| format.js do render :update do |page| page.insert_html :top, "issues", “<li>Nuevo!</li>” end end end
    49. 49. respond_to do |format| format.js do render :update do |page| page.visual_effect :highlight “issues” end end end
    50. 50. respond_to do |format| format.js do render :update do |page| page.toggle “issues” end end end
    51. 51. respond_to do |format| format.js do render :update do |page| page.hide “issues” end end end
    52. 52. respond_to do |format| format.js do render :update do |page| page[‘issues’] end end end
    53. 53. respond_to do |format| format.js do render :update do |page| page[‘issues’].hide end end end
    54. 54. respond_to do |format| format.js do render :update do |page| page.alert(“Huye!”) end end end
    55. 55. respond_to do |format| format.js do render :update do |page| page << “doSomethingReallyCool();” end end end
    56. 56. demo

    ×