404 when sending JSON to RoR with curl - ruby-on-rails

I'm very new to RoR, and I'm learning on the fly. With that being said, I'm trying to parse a POST request sent from Formstack to my script. I can view and run the script by going to it's URL and it works just fine, put when I point the Webhook in Formstack to the URL, nothing happens. I ran the below curl request from my command line, and it returned a 404 error.
curl -H "Content-Type: application/json" -d '{"FormID":"1234","UniqueID":"1234","Name":{"first":"John","last":"Smith"},"Email":"test#gmail.com","Phone":"(555) 555-555","Company":"Test Company"}' -X POST "http://scripturl.com"
I checked the data being sent with requestb.in, and everything is being sent properly. So why would it return a 404 error when JSON data is being sent, but run just fine when I view it in my browser? My sample code is below.
firstName = params[:Name]["first"]
lastName = params[:Name]["last"]
email = params["Email"]
company = params["Company"]
phone = params["Phone"]
client.create('contact', firstname: firstName, lastname: lastName, emailaddress1: email, subject: "Test", companyname: company, mobilephone: phone)
Here is the contents of log/production.log:
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.3) lib/rails/engine.rb:518:in `call'
railties (4.2.3) lib/rails/application.rb:165:in `call'
passenger (5.0.13) lib/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request'
passenger (5.0.13) lib/phusion_passenger/request_handler/thread_handler.rb:157:in `accept_and_process_next_request'
passenger (5.0.13) lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
passenger (5.0.13) lib/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
passenger (5.0.13) lib/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception'

I found the problem. I had to add the following into config/routes.rb:
post '/add' => 'contacts#add'
And then in controllers/application_controller.rb, you need to replace this:
protect_from_forgery with: :exception
With this:
protect_from_forgery with: :null_session

Related

Flexirest to handle string array

I'm using Flexirest to make a request to an endpoint that returns an array of strings with Content-Type: application\json.
This is the model:
class Neighborhood < BaseModel
get :by_location, "/neighborhoods/by_location"
end
And this is how I make the request:
def get_neighborhood_list
city_to_use = ApplicationHelper.user_location[:city] || Rails.configuration.default_location[:city]
#hoods = Neighborhood.by_location(city: city_to_use)
end
And this is called but it only reaches the super line since it breaks inside there:
def handle_response(response, cached = nil)
result = super(response, cached)
setup_paging_variables result, response
setup_paging_variables result.data, response if result.respond_to? 'data'
result
end
The endpoint returns an array of strings:
[
"Ahwatukee Foothills Village",
"Alhambra",
"Camelback East Village",
"Central City",
]
With this headers
My problem is that Flexirest is treating the strings as json objects instead due to the value on the Content-Type header.
I get this error
TypeError: no implicit conversion of Symbol into Integer
on this line on the if attributes[:_links].
It's getting there because hal_response? is true
Do I need to do something in particular in order for Flexirest to stop behaving like this?
Update
I guess I didn't explained it properly. The error is occurring on the gem side.
Here is the full error:
TypeError - no implicit conversion of Symbol into Integer:
flexirest (1.5.5) lib/flexirest/request.rb:612:in `handle_hal_links_embedded'
flexirest (1.5.5) lib/flexirest/request.rb:553:in `new_object'
flexirest (1.5.5) lib/flexirest/request.rb:704:in `block in generate_new_object'
flexirest (1.5.5) lib/flexirest/request.rb:703:in `generate_new_object'
flexirest (1.5.5) lib/flexirest/request.rb:501:in `handle_response'
config/initializers/01_flexirest.rb:7:in `handle_response'
flexirest (1.5.5) lib/flexirest/request.rb:219:in `block (2 levels) in call'
faraday (0.9.2) lib/faraday/response.rb:57:in `on_complete'
flexirest (1.5.5) lib/flexirest/request.rb:200:in `block in call'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
flexirest (1.5.5) lib/flexirest/request.rb:156:in `call'
flexirest (1.5.5) lib/flexirest/mapping.rb:46:in `_call'
flexirest (1.5.5) lib/flexirest/mapping.rb:28:in `block in _map_call'
app/controllers/application_controller.rb:93:in `get_neighborhood_list
The if attributes[:_links] line is part of the gem code, and it's here on this line
When it reaches this line the value of attributes is one of the strings inside the response, for instance: attributes = "Ahwatukee Foothills Village". That's why it gives the error.
What I'm trying to figure out if there is a way (maybe something in the configuration) that I can use Flexirest to handle this kind of responses.
This is a old question but thought I'd answer it. you need to add
plain: true
in your model like below.
class Neighborhood < BaseModel
get :by_location, "/neighborhoods/by_location", plain: true
end
It will then return the string array

production-only error ActionView::Template::Error (can't convert Symbol into Integer)

I am attempting to deploy a site onto engineyard and I keep getting an error that seems to be a data formatting error. This only happens when deployed as production onto the server cluster. using the same DB and codebase locally or on a VPS we have no issues.
The errors seem to me to show that suddenly there is an array / hash type mismatch with some of the user data. It always seems to trace back to the model where it is tasked to get 'options'. The errors are triggered by the templates calling for access of checks on user attributes.
production log:
Completed 500 Internal Server Error in 32ms
** [Airbrake] Failure: Net::HTTPClientError
ActionView::Template::Error (can't convert Symbol into Integer):
18: = admin_user.username
19: = username_helper(admin_user)
20: %td= country_image admin_user
21: %td= admin_user.account_name
22: %td
23: - if admin_user.is_a?(Creative)
24: - if admin_user.is_juror?
app/models/user.rb:79:in `[]'
app/models/user.rb:79:in `has_option?'
app/models/contest_holder.rb:77:in `is_client_type?'
app/models/contest_holder.rb:81:in `is_agent?'
app/models/contest_holder.rb:70:in `ao_client_name'
app/models/contest_holder.rb:115:in `account_name'
app/views/admin/users/_users.html.haml:21:in `block in _app_views_admin_users__users_html_haml__845309245401675393_70184787547360'
trace:
ActionView::Template::Error: can't convert Symbol into Integer
Sample stack trace (show Rails)
/app/models/user.rb: 79:in `[]'
/app/models/user.rb: 79:in `has_option?'
…P/releases/20130814153250/app/models/contest_holder.rb: 77:in `is_client_type?'
…P/releases/20130814153250/app/models/contest_holder.rb: 81:in `is_agent?'
…P/releases/20130814153250/app/models/contest_holder.rb: 70:in `ao_client_name'
…P/releases/20130814153250/app/models/contest_holder.rb: 115:in `account_name'
…1/gems/haml-4.0.3/lib/haml/helpers/action_view_mods.rb: 10:in `block in render_with_haml'
…ed_gems/ruby/1.9.1/gems/haml-4.0.3/lib/haml/helpers.rb: 89:in `non_haml'
…1/gems/haml-4.0.3/lib/haml/helpers/action_view_mods.rb: 10:in `render_with_haml'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb: 68:in `block in call'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb: 56:in `each'
…ms/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb: 56:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 184:in `call!'
…uby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/strategy.rb: 164:in `call'
…ruby/1.9.1/gems/omniauth-1.1.4/lib/omniauth/builder.rb: 49:in `call'
…VP/releases/20130814153250/lib/middleware/force_ssl.rb: 8:in `call'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb: 35:in `block in call'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb: 34:in `catch'
…ems/ruby/1.9.1/gems/warden-1.2.1/lib/warden/manager.rb: 34:in `call'
…ndled_gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/etag.rb: 23:in `call'
…/ruby/1.9.1/gems/rack-1.4.5/lib/rack/conditionalget.rb: 25:in `call'
…/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 210:in `context'
…/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb: 205:in `call'
…es/20130814153250/config/initializers/session_store.rb: 10:in `call'
code from user.rb which seems to be the point of contact for the error:
def has_option?(option)
self.options[option] && self.options[option].to_s == "1"
end
an example of an options value:
--- !map:ActiveSupport::HashWithIndifferentAccess is_agent: "1"
Came to find out that the issue was an additional line break within the database file. Specifically the application uses serialized yaml data a fair amount. An additional line break had been added between the yaml hash key and value causing an error within the object. We initially tried creating a script to cleanse the db and came to find it seemed to be simply corrupt from the original db file.
This was what wrong with my case
Error : ActionView::Template::Error (can't convert Symbol into Integer)
Reason:
In my haml.
I was trying to access a property from a json object.
object[:key]
But actually it was a json array(Array of entities from active record where clause). I just filtered the first element.
Hope someone will find useful.

Rails: Fedena webpage has a redirect loop error. No method error undefined method config_value for nil:NilClass

i have installed fedena (rails application) in my website
http://www.technoadmin.com/
i have installed all plugins, gems, created and migrated the db.
i have created the symbolic link like this
ln -s ~/fedena/public ~/public_html
when visiting my webpage it shows
This webpage has a redirect loop
so please help me. i am a newbie.i have tried to install this
application for the last
one month. i think i have reached the final step. so please help me to
solve this error.i will be very thankful to you.
and my production logfile is
# Logfile created on Fri Jul 26 14:55:03 +0530 2013
Processing UserController#login (for 182.73.241.18 at 2013-07-26 15:00:48) [GET]
Parameters: {"action"=>"login", "controller"=>"user"}
[FedenaRescue] No method error undefined method `config_value' for nil:NilClass
NoMethodError (undefined method `config_value' for nil:NilClass):
app/controllers/application_controller.rb:319:in `set_user_language'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in `send'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in `evaluate_method'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:225:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:629:in `run_before_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:615:in `call_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `send'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in `process'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:106:in `call'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:180:in `start'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/helper-scripts/passenger-spawn-server:99
Redirected to http://technoadmin.com/user/dashboard
These are the lines from 310 to 325 and i have only 325 lines in my application_controller.rb
return #local_tzone_time
end
private
def set_user_language
lan = Configuration.find_by_config_key("Locale")
I18n.default_locale = :en
Translator.fallback(true)
if session[:language].nil?
I18n.locale = lan.config_value
else
I18n.locale = session[:language]
end
News.new.reload_news_bar
end
end
the problem is with a method called config_value
NoMethodError (undefined method config_value' for nil:NilClass): app/controllers/application_controller.rb:319:inset_user_language'
so check your application_controller.rb on line 319 and post what's there
EDIT:
in your code (line 319), you're calling config_value on lan - but the error message is saying that lan has a nil value - so config_value can't be called on it.
earlier you have lan = Configuration.find_by_config_key("Locale") - so i'm guessing that rails can't find a config_key called "Locale" - but really I'm not sure. Did you write this code or was it generated by a gem?
I had this same issue when trying to setup Fedena on Ubuntu 20.04 using Docker.
Each time I try accessing the application on my browser on http://server-address:8080:/user/dashboard, I get a redirection. And then on my console, I get the error:
web_1 | Processing UserController#dashboard (for 103.89.5.96 at 2020-10-25 18:33:15) [GET]
web_1 | Parameters: {"controller"=>"user", "action"=>"dashboard"}
web_1 | [FedenaRescue] No method error undefined method `config_value' for nil:NilClass
web_1 |
web_1 | NoMethodError (undefined method `config_value' for nil:NilClass):
web_1 | app/controllers/application_controller.rb:342:in `set_user_language'
Here's how I fixed it:
Note: This is a temporary fix as I did not have a lot of time to dig into the codebase.
The issue emanates from this code in the app/controllers/application.rb file:
private
def set_user_language
lan = Configuration.find_by_config_key('Locale')
I18n.default_locale = :en
Translator.fallback(true)
I18n.locale = if session[:language].nil?
lan.config_value
else
session[:language]
end
News.new.reload_news_bar
end
I presume that the action set_user_language tries to set up a language for the user based on the default locale language set up on his/her machine/application or the session language, but then the config_value method called on Ian in lan.config_value seems to be Nil.
And this causes the redirect error since it is invoked in the app/controllers/application.rb using a before_filter:
before_filter :set_user_language
So it is called/invoked before any action is completed in the application.
A temporary fix will be to comment out the before_filter for it defined at the top of the app/controllers/application.rb file:
# before_filter :set_user_language
Now you can try accessing the page again.
You can as well consider running the command rake db:seed to seed the data in the db/seed.rb file into the database since it contains some important data that the application will need in order to run smoothly. And it also seems to contain the config_value data for the Configuration.
That's all.
I hope this helps

Error while upgrading to Rails 2.3.11 (HashWithIndifferentAccess error)

Whenever I attempt to create or update an environment that our app uses, I get the following:
NoMethodError (undefined method `base_url' for #<HashWithIndifferentAccess:0x107162f08>):
app/controllers/environments_controller.rb:64:in `check_base_url_for_https'
app/controllers/environments_controller.rb:56:in `update'
haml (3.0.22) lib/sass/plugin/rack.rb:41:in `call'
airbrake (3.0.4) lib/airbrake/rack.rb:27:in `call'
airbrake (3.0.4) lib/airbrake/user_informer.rb:12:in `call'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:82:in `start'
As I stated in the title, I recently upgraded to Rails 2.3.11. This error never occurred before. Here is the code in my environments_controller.rb that is being executed when the error occurs:
def check_base_url_for_https
#environment = params[:environment]
if /^https:\/\//i =~ #environment.base_url
#ajax_flash = "<ul class='notice'><li>The website you are trying to test is a secure site. If you are using self-signed SSL certificates please see our <a href='http://support.janova.us'>Support Site</a> and search for SSL for important tips on how to access your site.</li></ul>"
end
end
Does anyone know why this code (specifically the line if /^https:\/\//i =~ #environment.base_url no longer works in Rails 2.3.11?
I would like to add that the code in my app/models/environment.rb appears to be sound too:
def base_url
self[:base_url].try(:gsub, /\$/, '')
end
Does anyone see anything wrong with the code above?
I figured it out: params[:environment] was defined as a hash. Thank you, Frost, for forcing me to see this. Therefore, I changed the line #environment = params[:environment] to #environment = Environment.new(params[:environment]) and it worked.

Routing Error during "Ruby on Rails-Tutorial"

It seems like some people here had this problem but I couldn't find any solution in another topic.
I am doing Chapter 3 of the Ruby on Rails-Tutorial, working on the static pages. When I want to open them on the localhost it gives me a "Routing Error" in the Browser.
My Ruby is currently on version 1.9.3.
My Rails is currently on version 3.2.
I have tried:
restarting the server
saving all the files again
checking any issues in the static_pages_controller.rb
checking any issues in the routes.rb
checking any issues in the static_oages_spec.rb
Also there are no bugs in the HTML code of the single static page. And I can't find any more help in the tutorial, neither in other questions here on StackOverflow.
Edit:
This is the actual error message from the browser:
Routing Error
No route matches [GET] "/static_pages/home" Try running
rake routes for more information on available routes.
if I go to http://localhost:3000/static_pages/home, to one of three static pages I have.
This is routes.rb:
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
end
Also, I tried "rake routes" in the terminal, too. This is the result:
home_static_pages GET /static_pages/home(.:format) static_pages#home
help_static_pages GET /static_pages/help(.:format) static_pages#help
about_static_pages GET /static_pages/about(.:format) static_pages#about
static_pages POST /static_pages(.:format) static_pages#create
new_static_pages GET /static_pages/new(.:format) static_pages#new
edit_static_pages GET /static_pages/edit(.:format) static_pages#edit
GET /static_pages(.:format) static_pages#show
PUT /static_pages(.:format) static_pages#update
DELETE /static_pages(.:format) static_pages#destroy
And this is the error message the server is giving me:
Started GET "/static_pages/home.html" for 127.0.0.1 at 2012-04-03 13:23:54 +0200
ActionController::RoutingError (No route matches [GET] "/static_pages/home.html"):
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Try this :
match "/static_pages/home" => "static_pages#home", :via => :get
match "/static_pages/help" => "static_pages#help", :via => :get
match "/static_pages/about" => "static_pages#about", :via => :get
Add into routes , restart the server and refresh browser .
If you are using Spork you must re-run Spork so your tests will consider the changes in config files like routes.rb, that are pre-loaded with Spork, so are not automatically updated.
Stop Spork (Ctrl + C)
Run Spork again (bundle exec spork)
Source: this is the source of this information
"after changing a file included in the prefork loading (such as routes.rb), you will have to restart the Spork server to load the new Rails environment.
If your tests are failing when you think they should be passing, quit the Spork server with Control-C and restart it
your routes.rb file has problems, use either RESTful style:
resource :static_pages do
collection do
get :home
get :help
get :about
end
end
or the non RESTful style:
match "static_pages/home", :controller => "static_pages", :action => "home"
match "static_pages/help", :controller => "static_pages", :action => "help"
match "static_pages/about", :controller => "static_pages", :action => "about"
for more details please refer to official guide: http://guides.rubyonrails.org/routing.html
I had a few problems working through the Rails Tutorial, and it helped to be able to consult the author's GitHub repo: https://github.com/railstutorial
Find the file you're working on and compare it line by line. Or just cut and paste the full file and see if it will run, then track down your error.
If you check the routes.rb in config you'll probably find that the there is a 'e' missing from /home. Add that and you are golden. Or green. Or whatever :)
check your http:// address, specifically if you are on localhost:3000/path or localhost:3000/path1/path2, etc
Once you change the format of your mapping from get to match you will not need static_pages anymore, just go straight to localhost:3000/pagename e.g localhost:3000/about
From Ruby 2 to Ruby 3 there are some differences, but still the documentation for 3 is not easy to be found. There should be a tutorial only for that: practical differences between rails 2 and 3.
The guide provided by downloading Ruby on rails is "The book of ruby" but it's not good anymore. It should at least contain an advice at the beginning of chapter 19.
In
config/routes.rb
uncomment
root :to => 'welcome#index'

Resources