<%= will_paginate #semails, :renderer => 'RemoteLinkRenderer' , :remote => {
:loading => 'loadingPanel.show()',:complete => 'loadingPanel.hide()'} %>
in rails2
how to convert this to rails3
This is the routes using for rails 2 for semails
map.resources :users,
:collection => {:uapload_avatars => :post, :aselect_friend => :get, :alist_friend => :get, :aist_moderator => :get},
:member => {:anew_avatars => :get, :acreate_avatar => :post
} do |user|
user.resources :semails, :collection => { :sort => :get, :asave_draft => :post }
end
how to convert this routes in rails 3 ?
I'm facing this error
will clicking the pagination link it just redirecting to the home page is that routes issue or will paginate issue in rails 3
please help me to solve this issue
I'm not 100% about the spelling but the new routes for rails would approximate something like this:
resources :user do
collection do
post "uapload_avatars"
get "aselect_friend"
end
resources :semails do
collection do
get "sort"
post "asave_draft"
end
end
end
http://guides.rubyonrails.org/routing.html
Related
I'm using: Rails 3.1.3, HAML and Passenger
I'm having a route problem in my staging branch, but in the other branch that was merged into staging I have no problem at all. I've tried comparing my routes files and the form files from these two branches using git diff but the two files are the same in the branches.
A weird thing is the rendered error page. Here's a link to an screenshot
Error message
And also the error from passenger:
Rendered time_entries/_form_fields.haml (173.2ms)
Rendered time_entries/_form.haml (194.7ms)
Rendered time_entries/edit.haml within layouts/application (196.6ms)
Completed 500 Internal Server Error in 448ms
ActionView::Template::Error (No route matches {:controller=>"time_entries"}):
5: .field
6: = form.submit "Save"
7: |
8: = link_to "Cancel", project_time_entries_path(#project)
app/views/time_entries/_form.haml:8:in `block in _app_views_time_entries__form_haml__894171410_105032920'
app/views/time_entries/_form.haml:3:in `_app_views_time_entries__form_haml__894171410_105032920'
app/views/time_entries/edit.haml:2:in `_app_views_time_entries_edit_haml__805073897_105087770'
I attach you the code from my route and my form
form.haml
.app-form
= error_messages_for :time_entry
= form_for [#project, #time_entry] do |form|
= render :partial => 'form_fields', :locals => {:form => form}
.field
= form.submit "Save"
|
= link_to "Cancel", project_time_entries_path(#project)
routes.rb
Titi::Application.routes.draw do
root :to => 'time_entries#index'
match 'home' => 'home#index', :as => :home
match '/api/*other' => TitiAPI
resources :projects do
member do
get 'archive'
get 'unarchive'
end
resources :viewers
resources :labels
resources :time_entries do
collection do
get 'start'
end
member do
get 'new_note'
put 'add_note'
end
end
end
resources :bookings
resources :technical_orientations, except: [:delete]
match 'merge_labels/:projects_id' => 'labels#merge_labels', :as => :merge_labels
match 'move_labels/:projects_id' => 'labels#move_labels', :as => :move_labels
resources :time_entries do
collection do
get 'start'
end
member do
get 'new_note'
put 'add_note'
end
end
resources :users do
member do
get 'time_entries'
get 'edit_password'
put 'update_password'
get 'suspend'
get 'unsuspend'
end
new do
get 'invite_form'
post 'invite'
end
collection do
get 'all'
end
end
resources :user_sessions
match 'reports/timesheet' => 'reports#timesheet', :as => :timesheet
match 'reports/:week/timesheet' => 'reports#timesheet', :as => :timesheet_week
match 'reports/timesheet_detail' => 'reports#timesheet_detail', :as => :timesheet_detail
match 'reports/dashboard' => 'reports#dashboard', :as => :dashboard_report
match 'reports/timeentries_irregulars' => 'time_entries_irregulars#timeentries_irregulars', :as => :timeentries_irregulars
match 'reports/:week/timeirregulars' => 'time_entries_irregulars#timeentries_irregulars', :as => :timeirregulars_week
match 'reports/timesheet/admin' => 'reports#timesheet_admin', :as => :timesheet_admin
match 'reports/:week/timesheet/admin' => 'reports#timesheet_admin', :as => :timesheet_admin_week
match 'reports/time_entries' => 'time_entries_reports#landing_report'
match 'reports/time_entries/make' => 'time_entries_reports#index'
match 'reports/time_entries/csv' => 'time_entries_reports#make_csv'
match 'reports/:token' => 'reports#index', :as => :reports
match 'login' => 'user_sessions#new', :as => :login
match 'logout' => 'user_sessions#destroy', :as => :logout
match 'register' => 'users#register', :as => :register
resources :companies do
collection do
get 'settings'
get "remove_photo"
end
end
match 'labels/for_project_id/:id' => 'labels#for_project_id', :as => :for_project_id
match 'holidays_for_company/:token' => 'holidays#public', :as => :public_holiday_for_company
match 'holidays_by_year' => 'holidays#by_year', :as => :holidays_by_year
resources :holidays
resources :clients
resources :invoices do
member do
get 'pdf_invoice'
get 'cancel'
end
resources :invoice_lines do
collection do
get 'add'
end
end
resources :payments
end
resources :tweets do
resource :tweet_likes, :path => 'likes' do
collection do
get 'names'
end
end
end
match 'select_invoices' => 'invoices#select_invoices', :as => :select_invoices
match 'pusher/auth' => 'pusher#auth'
resources :requests, :only=>[:create]
match '*request', :controller => 'requests', :action => 'options', :constraints => {:method => 'OPTIONS', :format => 'json'}
end
Thank's in advance.
On app/views/time_entries/_form.haml:8, does #project exist? Perhaps your staging branch uses a different database and hence the #project you think is there is not?
Also, run rake routes and verify the project_time_entries is in the output. Perhaps you need a :as on one of your routes.
I'm trying to write a blog in Rails 3, so I have posts. I want to make nice routes for the posts like this: posts/year/month/day/post-title. So I overrided to_param in model/post.rb and use friendly_id for title:
extend FriendlyId
friendly_id :title, :use => :slugged
def to_param
"#{year}/#{month}/#{day}/#{title.parameterize}"
end
And I added this to routes.rb:
resources :posts do
collection do
match ":year/:month/:day/:id", :action => "show"
end
member do
post 'comment'
delete 'comment/:comment_id', :action => 'destroy_comment', :as => 'destroy_comment'
end
end
In show this works:
<%= link_to image_tag("/images/edit_icon.png"),
{ :controller => 'posts', :action => 'edit' }, :id => #post %>
But in index it says
routing error:
No route matches {:action=>"edit", :controller=>"posts"}.
I'm new to Rails and I haven't managed to find out what causes this error. Can anyone help me figure out what I do wrong?
OK, I've been having relative success with RESTful authentication. I followed this tutorial to add the capability to change the password. The problem is that tutorial is written for rails 2.3 and I'm using rails 3.
The code used in my controller and view are exactly as they are in the tutorial
I added to routes.rb:
match '/change_password' => 'users#change_password', :as => :change_password
resources :users, :controller => 'users', :collection => {:change_password_update => :put}
Now i get this error: undefined method `change_password_update_user_path'
the comments to the tutorial mentioned that exact error, and they said the solution is in the routing, but given the routing differences between 2.3 and 3, I'm really just guessing what needs to go in there. Any idea how i can get this working?
all i had to do is change
<% form_tag change_password_update_user_path(current_user), :method => :put do |f| %>
to
<% form_tag '/change_password_update', :method => :put do |f| %>
and put this in my routes.rb
match '/change_password' => 'users#change_password', :as => :change_password
match '/change_password_update' => 'users#change_password_update', :as => :change_password_update
resources :users, :controller => 'users', :collection => {:change_password_update => :put}
Rails is giving me a route error even though the route appears to
be in the route list.
The form is doing a Post to try to hit the update route on the Admin::ProductsController.
The edit route, index route, and show route work fine.
Using Rails 3.0.5 and ruby 1.9.2
Anyone have an idea? I can't seem to see the problem.
Error
No route matches "/admin/products/2039"
Code from ERB File that is generating the form
<%= form_for :product, #product, :url => { :action => "update" } do |f| %>
Products Controller method at this point is just a stub of
def update
puts params.inspect
end
Routes File
Analytics::Application.routes.draw do
match 'login' => 'Authentication#login', :via => [:get, :post]
namespace :admin do
# Directs /admin/products/* to Admin::ProductsController
# (app/controllers/admin/products_controller.rb)
root :to => 'AdminInterface#index', :via => :get
resources :products
resources :publishers, :only => [:edit, :update]
match 'publishers/query/:subset' => 'Publishers#index', :as => :publishers_subset, :via => [:get, :post]
end
end
According to your routes, shouldn't that be
= form_for [:admin, #product] do |f|
Your form_for can just be:
<%= form_for #product do |f| %>
If #product is an existing object then it will automatically know to go the update action of the ProductsController.
I have a form that is suppose to be a POST to CREATE action but it is doing a POST to INDEX action. So i then decided to test my routes with rspec. In my Example i have my test as follows.
it "should recognize a specific invoices#create route" do
assert_routing("/invoices", {:controller => "invoices", :action => "create"})
end
but when i run the test its coming up with this error.
1) InvoicesController on get to :index should recognize a specific invoices#create route
Failure/Error: assert_routing("/invoices", {:controller => "invoices", :action => "create"})
The recognized options <{"action"=>"index", "controller"=>"invoices"}> did not match <{"controller"=>"invoices", "action"=>"create"}>, difference: <{"action"=>"create"}>.
Expected block to return true value.
So im trying to figure out why my form is doing a POST on INDEX and why my test thinks im doing an index route. I have tried inserting :method => :post in the test but it doesnt seem to work.
Have you tried this?:
assert_routing({ :path => "invoices", :method => :post },
{ :controller => "invoices", :action => "create" })