0

I'm very green to ruby on rails and have been working on getting an application working with mysql, everything works except for one particular page when loading assets from mysql database.

I'm not sure what is going on and have not had luck fixing it.

I'm running on ubuntu, with passenger 4.0.20, mysql 2.9.1 gem, rails 3.0.7,

when viewing the page either under the passenger daemon or through strictly apache the app returns this:

Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== 'assets')' at line 1: SELECTtypes.* FROMtypesWHERE (type_for == 'assets')

Extracted source (around line #52):

49:   </div>
50:   <div class="field">
51:     <%= f.label :asset_type_id %><br />
52:     <%= f.select :asset_type_id, Type.where("type_for == 'assets'").collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {}  %>    
53:   </div>
54:   <div class="field">
55:     <%= f.label :asset_status_id %><br />  

app/views/assets/_form.html.erb:52:in `block in_app_views_assets__form_html_erb___1678548858904611904_30514700_2370109183913626002'
app/views/assets/_form.html.erb:1:in         `_app_views_assets__form_html_erb___1678548858904611904_30514700_2370109183913626002'
app/views/assets/new.html.erb:3:in `_app_views_assets_new_html_erb___211939086717483877_30551560__3850816556217762359'

I'm at my end of possible things to try, not really sure where to go with this. Any help would be amazing right now.

1
  • edit your post clearly... Commented Apr 24, 2014 at 16:13

2 Answers 2

1

You have to remove == from line 52 and replace with just =

52:     <%= f.select :asset_type_id, Type.where("type_for = 'assets'").collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {}  %>    
Sign up to request clarification or add additional context in comments.

Comments

1

You have a syntax error on this line

<%= f.select :asset_type_id, Type.where("type_for == 'assets'").collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {} %>

it should be like this

<%= f.select :asset_type_id, Type.where("type_for" => "assets").collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {} %>

OR

you can write it as

<%= f.select :asset_type_id, Type.where("type_for = ?", "assets").collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {} %>

OR

<%= f.select :asset_type_id, Type.where(:conditions =>["type_for = ?", "assets"]).collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {} %>

And As @MikeCampbell pointed,it can also written as

<%= f.select :asset_type_id, Type.where("type_for" :"assets").collect{|u| [ u.name, u.id ]} , { :include_blank => true }, {} %>

4 Comments

"type_for ?" should be "type_for = ?".
"type_for" = "assets" should be "type_for" => "assets" too, or preferably type_for: "assets"
@MikeCampbell Thanks! It is hard to believe i missed that.
Thanks yeah it was the == vs =. that did the trick. Was looking me right in the face. I'm so glad stackoverflow is a thing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.