Current View | Target View | Helper Method | Answers |
---|---|---|---|
index | show | photo_path(photo) | user_photo_path(@user, photo) |
index | edit | edit_photo_path(photo) | edit_user_photo_path(@user, photo) |
index | new | new_photo_path | new_user_photo_path(@user) |
show | edit | photo_path(@photo) | edit_user_photo_path(@user, @photo) |
show | index | photo_path(@photo) | user_photos_path(@user) |
edit | show | photo_path(@photo) | user_photo_path(@user, @photo) |
> rails server -p 5678or
> rails s -p 5678
http://localhost:3000/client_server/server?utf8=%E2%9C%93 &name=Alice&gender=F&age=11&commit=Submit+Info+to+Server
<form accept-charset="UTF-8" action="server" method="get"> <div style="margin:0;padding:0;display:inline"> <input name="utf8" type="hidden" value="✓" /> </div> <p>Information to be sent to server:</p> <p>Name:<br /> <input id="name" name="name" type="text" value="" /> </p> <p>Gender:<br /> <input id="gender" name="gender" type="text" value="" /> </p> <p>Age:<br /> <input id="age" name="age" type="text" value="" /> </p> <p> <input name="commit" type="submit" value="Submit Info to Server" /> </p> </form>
<form accept-charset="UTF-8" action="server" method="post"> <div style="margin:0;padding:0;display:inline"> <input name="utf8" type="hidden" value="✓" /> <input name="authenticity_token" type="hidden" value="eTrDAIO+fK9L4KKV/KJChNebleeSIdzmgjor6VZJdss=" /> </div> </form>
resources :items
http://localhost:3000/patients http://localhost:3000/patients/3
http://localhost:3000/patients.json http://localhost:3000/patients/3.json
# GET /patients # GET /patients.json def index @patients = Patient.all # Insert code here: respond_to do |format| format.html format.xml { render xml: @patients } end # End of inserted code. end # GET /patients/1 # GET /patients/1.json def show # Insert code here: respond_to do |format| format.html format.xml { render xml: @patient } end # End of inserted code. endNow obtain XML output with these URLs:
http://localhost:3000/patients.xml http://localhost:3000/patients/3.xml
------- Controller ------------------ class ConvertController < ApplicationController def input @c = 0 end def display @c = params[:cel].to_i @f = 9 * @c / 5 + 32 end end -------- input view -------------------- <h1>Temperature Converter</h1> <%= form_tag 'display' do %> <p><%= text_field_tag :cel, @c.to_s %></p> <p><%= submit_tag 'Convert' %></p> <% end %> -------- display view ------------------ <h1>Temperature Converter</h1> <p>Celsius: <%= @c %></p> <p>Fahrenheit: <%= @f %></p> <p><%= link_to "Input Page", convert_input_path %></p> -------- routes file Rails.application.routes.draw do get 'convert/input' get 'convert/display' post 'convert/display' end