I added the gem 'event-calendar', :require => 'event_calendar'
bundled
rails generate event_calendar
migrated
changed
match '/calendar(/:year(/:month))' => 'calendar#index', :as => :calendar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/}
to
get '/calendar(/:year(/:month))' => 'calendar#index', :as => :calendar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/}
went to
http://localhost:3000/calendar/
and I got myself a pretty blingin calendar, was just wondering how do you now add crud actions to it? I have been looking at the documents and find it rather confusing.
You're probably going to want to make an Events Controller and define the CRUD actions inside there.
Related
I am upgrading application from rails 2.3/x to 3.2.x
I have a old route like this:
map.calendar '/calendar/:year/:month', :controller => 'calendar', :action => 'index', :year => Time.now.year, :month => Time.now.month
rake routes generate something like this:
calendar /calendar/:year/:month {:controller=>"calendar", :action=>"index"}
I am not sure what is year and month here, are they default values being sent in case none is given? What would be its rails 3.2.x syntax.
I tried something like this:
match '/calendar/:year/:month' => 'calendar#index', :defaults => {:year => Time.now.year, :month => Time.now.month}
The route generated in rails 3.2.x is:
/calendar/:year/:month(.:format) calendar#index {:year=>2013, :month=>9}
Help me out to convert this route correctly.
You should add as key to your match call:
match '/calendar/:year/:month' => 'calendar#index', :defaults => {:year => Time.now.year, :month => Time.now.month}, :as => 'calendar'
My rails app is set to use subdomains as described in this RailsCast:
http://railscasts.com/episodes/221-subdomains-in-rails-3
However, right now, paths render like this:
http://organization.domain.com/organizations/1/edit
I have the controllers set up to choose the organization based on the subdomain already, so I'm wondering if there's a way to strip out the /organizations/:id portion of the paths, such that:
link_to edit_organization(#organization)
goes to http://organization.domain/edit, instead of http://organization.domain/organizations/:id/edit
Since there's going to be many nested resources within organizations (people, donations, etc), it's important that URL's don't end up incredibly long, and that the path generation method remains pretty straightforward.
Is there a way to do this?
You could use a route like:
resource :organization, :path => ""
The will cut down your url to 'http://organization.domain/:id/edit`.
Getting rid of the :id is tricky, and I dont think it can be done directly. What I would do is something like:
resource :organization, :path => "", :only => [] do
match "index", :via => :get
match "new", :via => :get
match "show", :via => :get, :constraints => {:subdomain => /[a-zA-Z]+/}
match "edit", :via => :get, :constraints => {:subdomain => /[a-zA-Z]+/}
match "update", :via => :put, :constraints => {:subdomain => /[a-zA-Z]+/}
match "create", :via => :post
end
Not very DRY, but I think it should work.
I'm trying to use the high_voltage gem to serve static pages in my Rails app. What I want is for individual sections to get their own folder, but can't quite get it to work & can't find a solution around the web.
What I want:
RAILS_ROOT/app/views/pages/(page) to be routed as '/(page)'
While RAILS_ROOT/app/views/pages/(directory)/(page) => '/(directory)/(page)'
Here's my attempt:
routes.rb:
Cam4::Application.routes.draw do
root :to => 'high_voltage/pages#show', :id => 'index'
match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
scope "ruby" do
match '/ruby/:id' => 'high_voltage/pages/ruby#show', :as => :static, :via => :get
end
end
Thanks a lot,
Cameron
Actually ended up solving the problem on my own using route globbing.
Given a Rails 3.2.5 app running high_voltage, with view paths:
RAILS_ROOT/app/views/pages/id [=> '/pages/id' or just '/id']
RAILS_ROOT/app/views/pages/ruby/id [=> 'pages/ruby/id' or 'ruby/id']
Routes.rb:
Cam4::Application.routes.draw do
root :to => 'high_voltage/pages#show', :id => 'index'
match '/*id' => 'high_voltage/pages#show', :as => :static, :via => :get
end
My question it's about use a filter by date in the route of a rails application, at the moment I all ready have the rule that match the pattern of the date in the routes.rb file, it's looks like this:
match "itineraries/:day/:month/:year" => "itineraries#index",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }
match "itineraries/new/:day/:month/:year" => "itineraries#new",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }
resources :itineraries
match '/:controller(/:action(/:id))'
root :to => "itineraries#index"
That match for example /itineraries/01/01/2011, the problem comes when I generate a route from the resource, for example, itineraries_path(:year=>2011,:month=>1,:day=>1) generate:
/itineraries?day=1&month=1&year2011
instead of
/itineraries/01/01/2011
Is there a way to put the match rule inside the resource mapping?
well, short answer is your route does exists, but it's not named yet (check rake routes to convince yourself) and that's why you can't call it just like that (using itineraries_path)
so, the correct way to do it would be for example:
match "itineraries/:day/:month/:year" => "itineraries#index",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ },
:as => "itineraries_date"
(notice the :as part)
now, if you call itineraries_date_path(11,12,1998) it will give you itineraries/11/12/1998
does anyone know if there is a rails routes converter online? I was not able to find one. I am trying to convert this line:
map.add_payment_profile 'add_payment_profile/:id', :controller => 'payment_profile_controller', :action => 'add_payment_profile'
Thanks!! So if I understand correctly:
map.create_cim_payment_profile 'create_cim_payment_profile_user', :controller => 'authorize_net', :action => 'create_cim_payment_profile', :only => :post would be
match 'create_cim_payment_profile_user' => 'payment_profile#create_cim_payment_profile', :as => :create_cim_payment_profile
I believe what you're looking for is
match 'add_payment_profile/:id' => 'payment_profile#add_payment_profile',
:as => :add_payment_profile
Rails 3 has a new controller#action shorthand for mapping controller actions. You will also need to specify :as to created a named route.
may be this will work:
match 'add_payment_profile/:id',:controller => "payment_profile_controller",
:action => "add_payment_profile"