SNEH PANDYA
SNEH PANDYA

Reputation: 797

Select_Tag not working in rails?

Here is my code for select_tag

<%= select_tag :tp, options_for_select([["movable",1],["fixed",2]]), :prompt => "select type of asset" %>

it works if i replace by:

<%= f.text_area :tp %>

If this in not enough i will give more code as you desire: here is the log after i use select_tag

Started POST "/assets" for 127.0.0.1 at 2014-03-07 23:40:34 +0530
Processing by AssetsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Gib6rSODjXgXLZ9+5sDcq0ZatkA7144hU+Em2X7KONU=", "asset"=>{"name"=>"", "location"=>"", "cost"=>""}, "tp"=>"1","commit"=>"Save"}
(1.0ms)  BEGIN
(1.0ms)  ROLLBACK
Redirected to http://localhost:3000new
Completed 302 Found in 5ms (ActiveRecord: 2.0ms)
[2014-03-07 23:40:34] ERROR URI::InvalidURIError: the scheme http does not accept registry part: localhost:3000new (or bad hostname?)
    F:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/uri/generic.rb:1203:in `rescue in merge'
     F:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/uri/generic.rb:1200:in `merge'
     F:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpresponse.rb:275:in `setup_header'
    F:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpresponse.rb:205:in `send_response'
    F:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:110:in'run'
    F:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'


Started GET "/assets/logo.png" for 127.0.0.1 at 2014-03-07 23:40:36 +0530

Error after changing to `real_assets_path

Started GET "/real_assets/new" for 127.0.0.1 at 2014-03-09 13:56:47 +0530
ActiveRecord::SchemaMigrationLoad(1.0ms)SELECT"schema_migrations".* FROM"schema_migrations"
Processing by AssetsController#new as HTML
Rendered assets/new.html.erb within layouts/application (30.0ms)
Completed 500 Internal Server Error in 98ms

ActionView::Template::Error (undefined method `assets_path' for #<# <Class:0x545bb78>:0x545aeb8>):
1: <div class = "container">
2: <div id = "assetnew">
3:  <%= form_for(@asset) do |f| %>
4:  <center><h1>Add Asset</h1></center>
5:   <div class = "well">
6:     <a class ="red">
  app/views/assets/new.html.erb:3:in`_app_views_assets_new_html_erb___457532114_11608392'


Rendered     

F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
 Rendered  

F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered  

F:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (18.0ms)

Upvotes: 0

Views: 192

Answers (1)

Richard Peck
Richard Peck

Reputation: 76784

Assets

This is the error Rails is returning:

ERROR URI::InvalidURIError: the scheme http does not accept registry part: localhost:3000new (or bad hostname?)

Without seeing your form, it seems you've got an issue with calling your resource /assets (as mentioned in the comments)

Basically, Rails treats the assets pipeline as a base directory - localhost:3000/your_asset_file.png -- it looks like this is what's happening here

Because your app is referencing /assets, I would surmise it's confusing it with the assets dir. Try doing this:

#config/routes.rb
resources :assets, as: "real_assets", path: "real_assets" #-> real_assets_path - /real_assets

Select

The select problem is likely caused by your assets path problem

select_tag is a standalone helper method (doesn't need any FormBuilder to help it). This means you should be able to just use it in an .html.erb file without any problems

The syntax for the select looks okay, so I'd recommend if you get your assets path fixed, you should be able to use it

Upvotes: 1

Related Questions