charles d
2011-Apr-17 21:16 UTC
unable to set default_url_options on per environment basis
Im trying to set the default_url_options on a per environment basis but nothing is working. I keep getting "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" post.rb def share_all url = Rails.application.routes.url_helpers.post_url(self) if user.authentications.where(:provider => ''twitter'').any? user.twitter_share(url) end end I''ve tried adding this to my config/environments/development.rb : development.rb config.action_controller.default_url_options = {:host => "localhost: 3000"} which didn''t work so I tried it this way: development.rb config.action_controller.default_url_options = {:host => "localhost", :port => 3000} And that didnt work so I tried just defining the method in the application controller but it didnt work either. class ApplicationController < ActionController::Base protect_from_forgery include ApplicationHelper def default_url_options { :host => "example.com"} end end What am I missing here? This is driving me nuts, thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Apr-18 13:05 UTC
Re: unable to set default_url_options on per environment basis
On Apr 17, 10:16 pm, charles d <barryfrombarryvi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Im trying to set the default_url_options on a per environment basis > but nothing is working. I keep getting "Missing host to link to! > Please provide :host parameter or set default_url_options[:host]" > > post.rb > > def share_all > url = Rails.application.routes.url_helpers.post_url(self) > if user.authentications.where(:provider => ''twitter'').any? > user.twitter_share(url) > end > end > > I''ve tried adding this to my config/environments/development.rb : > > development.rb > > config.action_controller.default_url_options = {:host => "localhost: > 3000"} > > which didn''t work so I tried it this way: > > development.rb > > config.action_controller.default_url_options = {:host => > "localhost", :port => 3000} > > And that didnt work so I tried just defining the method in the > application controller but it didnt work either. > > class ApplicationController < ActionController::Base > protect_from_forgery > include ApplicationHelper > def default_url_options > { :host => "example.com"} > end > end > > What am I missing here? This is driving me nuts, thanks.I think you''re not setting default_url_options in the correct place - you''re using the named routes module in isolation (whereas normally that code would be called from within a controller or helper) so the stuff you''re doing to ApplicationController doesn''t come into place. Rails.application.routes.default_url_options[:host]= ''example.com'' seems to do the trick Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
charles d
2011-Apr-20 20:39 UTC
Re: unable to set default_url_options on per environment basis
Thanks that worked perfectly On Apr 18, 6:05 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 17, 10:16 pm, charles d <barryfrombarryvi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Im trying to set the default_url_options on a per environment basis > > but nothing is working. I keep getting "Missing host to link to! > > Please provide :host parameter or set default_url_options[:host]" > > > post.rb > > > def share_all > > url = Rails.application.routes.url_helpers.post_url(self) > > if user.authentications.where(:provider => ''twitter'').any? > > user.twitter_share(url) > > end > > end > > > I''ve tried adding this to my config/environments/development.rb : > > > development.rb > > > config.action_controller.default_url_options = {:host => "localhost: > > 3000"} > > > which didn''t work so I tried it this way: > > > development.rb > > > config.action_controller.default_url_options = {:host => > > "localhost", :port => 3000} > > > And that didnt work so I tried just defining the method in the > > application controller but it didnt work either. > > > class ApplicationController < ActionController::Base > > protect_from_forgery > > include ApplicationHelper > > def default_url_options > > { :host => "example.com"} > > end > > end > > > What am I missing here? This is driving me nuts, thanks. > > I think you''re not setting default_url_options in the correct place - > you''re using the named routes module in isolation (whereas normally > that code would be called from within a controller or helper) so the > stuff you''re doing to ApplicationController doesn''t come into place. > > Rails.application.routes.default_url_options[:host]= ''example.com'' > > seems to do the trick > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.