Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## routes.rb
- ActionController::Routing::Routes.draw do |map|
- map.resources :users do |p|
- p.resources :posts
- end
- map.login "login", :controller => 'user_sessions', :action => 'new'
- map.logout "logout", :controller => 'user_sessions', :action => 'destroy'
- map.root :controller => 'pages'
- map.resources :user_sessions
- map.resources :password_resets
- map.connect ':controller/:action/:id'
- map.connect ':controller/:action/:id.:format'
- end
- ## posts/_form.html.erb
- <% form_for([:user,@post]) do |f| %>
- <%= f.error_messages %>
- <p>
- <%= f.label :title %><br />
- <%= f.text_field :title %>
- </p>
- <p>
- <%= f.label :content %><br />
- <%= f.text_area :content %>
- </p>
- <p><%= f.submit "Submit" %></p>
- <% end %>
- ## posts_controller.rb
- [...]
- def edit
- require_user
- @user = current_user
- @post = Post.find(params[:id])
- end
- def update
- @post = Post.find(params[:id])
- if @post.update_attributes(params[:post])
- flash[:notice] = "Successfully updated post."
- redirect_to root_url
- else
- render :action => 'edit'
- end
- end
- [...]
- ## posts/show.html.erb
- [...]
- <% if current_user.username = @user.username %>
- <%= link_to "Edit this post", edit_user_post_url %>
- <% end %>
- [...]
Add Comment
Please, Sign In to add comment