Ruby on Rails: undefined method 'role' for Class - ruby-on-rails

I'm haing a problem in my Ruby on Rails application. I have an entity called 'Hairdresser', with those properties:
irb(main):003:0> Hairdresser
=> Hairdresser(id: integer, name: string, surname: string, email: string, auth_token: string, password_digest: string, created_at: datetime, updated_at: datetime, facebook_id: string, first_login: boolean, role: string)
I also created some scaffold in order to create new Hairdresser entities, but when I click on "new hairdresser" I get the following error:
2016-03-17T09:14:43.063793+00:00 app[web.1]: ActionView::Template::Error (undefined method `role' for #<Hairdresser:0x007f9e20f2bc30>):
2016-03-17T09:14:43.063794+00:00 app[web.1]: 25: </div>
2016-03-17T09:14:43.063794+00:00 app[web.1]: 26: <div class="field">
2016-03-17T09:14:43.063795+00:00 app[web.1]: 27: <%= f.label :role %><br>
2016-03-17T09:14:43.063795+00:00 app[web.1]: 28: <%= f.text_field :role %>
2016-03-17T09:14:43.063795+00:00 app[web.1]: 29: </div>
Role is a property that I added AFTER the creation of the scaffold, but I also added it where it was supposed to be added (I think):
view/hairdressers/_form.html.erb
<div class="field">
<%= f.label :role %><br>
<%= f.text_field :role %>
</div>
view/hairdressers/index.html.erb, index.json.jsonbuilder, and in every other /view/hairdressers file.
The local version of the application is working, it could have something to do with the fact that Heroku is loading the production environment and on localhost I am running the development environment?
EDIT: this is the execution of heroku run rake --trace db:migrate
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
ActiveRecord::SchemaMigration Load (0.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
** Invoke db:_dump (first_time)
** Execute db:_dump

Make sure the migrations are run on heroku. https://devcenter.heroku.com/articles/rake
heroku run rake --trace db:migrate

Related

"NoMethodError: undefined method `type' for "character varying":String" after "rake db:migrate"

I tried to add check-ins to micro-posts but I've got an error after rake db:migrate.. What does it mean?
Error
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
NoMethodError: undefined method `type' for "character varying":String
add_checkin_to_microposts
class AddCheckinToMicroposts < ActiveRecord::Migration
def change
add_column :microposts, :location, :point, :geographic => true
end
end
database.yml
development:
adapter: postgresql
schema_search_path: public, postgis
encoding: unicode
database: blog_development
host: localhost
pool: 5
username: ********
password:
Assuming you are using the gem activerecord-postgis-adapter, you'd better try to change the database adapter to postgis as recommended in their official document:
https://github.com/rgeo/activerecord-postgis-adapter
the problem that you are having is that point method does not exist in ActiveRecord.
Instantiates a new column for the table. The type parameter is normally one of the migrations native types, which is one of the following: :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :time, :date, :binary, :boolean.
For more info pleas read http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column
Hope this helps

Application.css isn't precompiled error 500 rails

I have an error with rails + nginx + unicorn in production
ActionView::Template::Error (application.css isn't precompiled):
I'm trying to deploy clean rails app with sqlite3.
When i visit http://cayennepower.ru/posts i have We're sorry, but something went wrong error.
On front page the static welcome page works good.
In my app/log production.log i have such errors
Started GET "/posts" for 127.0.0.1 at 2012-12-12 06:47:48 +0100
Processing by PostsController#index as */*
Rendered posts/index.html.erb within layouts/application (0.4ms)
Completed 500 Internal Server Error in 3ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>CleanRails</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___741543018_80365330'
app/controllers/posts_controller.rb:7:in `index'
in config/enviroments/production.rb i placed
config.assets.compile = true
config.assets.precompile += %w( application.css )
i've run rake assets:precompile --trace RAILS_ENV=production
The trace log is
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rvm/rubies/ruby-1.9.3-p327/bin/ruby /usr/local/rvm/gems/ruby-1.9.3-p327/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
but i still has this error
my nginx.conf is
upstream cayennepower.ru {
server unix:/home/sites/cayennepower.ru/www/tmp/sockets/unicorn.sock;
# server 127.0.0.1:3000 fail_timeout=0;
}
my domain.conf file is
server {
listen 80;
server_name cayennepower.ru;
root /home/sites/cayennepower.ru/www/public;
try_files $uri/index.html $uri #unicorn;
location #unicorn {
#if (!-f $request_filename) {
proxy_pass http://cayennepower.ru;
break;
#}
}
}
Thank you very much for help guys!

heroku undefined method `name' for User

In my app it was User model without 'name' field, when I added this field by migration. On my localhost my sign up form works fine, but on heroku I have this log:
ActionView::Template::Error (undefined method `name' for #<User:0x0000000518fb00>):
Rendered users/new.html.haml within layouts/application (3.1ms)
5: = f.input :name, required: 'true'
6: = f.input :email, required: 'true'
3: %h1 Sign up
4: = simple_form_for #user do |f|
7: = f.input :password
8: = f.input :password_confirmation, required: 'true'
What I've tried:
heroku run rake db:migrate
heroku run rake db:reset
but nothing helped.
you also have to restart heroku after migrating - you'd want to run
heroku run rake db:migrate
heroku restart
Make sure you have done git add .. Then git status to make sure that all the files have been committed. Then try the push again. Then migrate again.

Rails 500 Error: application.css isn't precompiled

I've got Rails running on Passenger with Apache on an Ubuntu linux box (ve) Server from Mediatemple. My app is giving me a 500 error (a Rails error, not an Apache error) when I try to load any page: http://www.mvngmtns.com
I saw an article about changing this line in config/environments/production.rb:
config.assets.compile = true
But this didn't solve my problem. Can anyone help?
My development.log:
Started GET "/" for 72.225.170.239 at 2012-06-29 15:28:43 -0700
Processing by HomeController#index as HTML
Rendered application/_logo.html.erb (0.6ms)
Rendered application/_navbar.html.erb (1.4ms)
Rendered home/index.html.erb within layouts/application (2.6ms)
Completed 500 Internal Server Error in 6ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>Moving Mountains<%= get_title %></title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8:
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___2841110860658336572_129641540'
app/controllers/home_controller.rb:6:in `index'
As requested, ran
rake assets:precompile --trace RAILS_ENV=production
touch /tmp/restart.txt
but still the same error. Here's what the trace said:
newguy#mvngmtns:/var/www/movingmountains$ rake assets:precompile --trace RAILS_ENV=production
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rvm/rubies/ruby-1.9.2-head/bin/ruby /usr/local/rvm/gems/ruby-1.9.2-head#global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:non digest
I still have the same "500 - We're sorry, but something went wrong" in the browser, and cache: [GET /] miss in the apache log file.
After setting
config.assets.compile = true
you should also run:
rake assets:precompile --trace RAILS_ENV=production
See: rails 3.1.0 ActionView::Template::Error (application.css isn't precompiled)
I don't know details on Mediatemple, but perhaps you need to precompile your assets before deploying:
rake assets:precompile
A couple things:
check that the stylesheet actually gets compiled - it will be something like public/assets/application-XXX.css
Passenger looks for APP_DIR/tmp/restart.txt, not /tmp/restart.txt, so make sure you touch the file in the right place

Why am I seeing output during 'rake test' other than '.' 'F' or 'E' (ruby 1.9.2p290, Rails 3.0.9)?

When I used to run 'rake test' I would see either '.' or 'F' or 'E' for each test.
When all was well, the output was a line of '.'
Now, even though all my test are passing, I am seeing program output in the midst of the line of '.'
I am not sure the best way to post the output, but here is an initial offering:
perrys-MacBook-Pro:iway perry_mac$ rake test:functionals --trace
** Invoke test:functionals (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** Execute test:functionals
Loaded suite /Users/perry_mac/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
.........................."Welcome joe : "
."Welcome joe : "
."Welcome joe : "
."Welcome joe : "
.................."Welcome bob : "
...........
Finished in 0.998462 seconds.
58 tests, 81 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 15796
The line of code generating the output is:
app/views/layouts/application.html.erb
<div id="nav">
<% if current_user %>
<% str= "Welcome " + current_user.username + " : "%>
<%= p str %>
<%= link_to "Edit Profile : ", edit_user_path(current_user.id)%>
<%= link_to "Logout", :logout%>
<% else %>
<%= link_to "Register", new_user_path%> |
<%= link_to "Login", :login %>
<% end %>
</div>
The "Welcome joe : " and "Welcome bob : " msgs are expected program output seen after a user successfully logs in. bob and joe are usernames created in a fixtures file. I can't figure out why the msgs are now seen during 'rake test' I see the same behavior when --trace is not used as well. Please comment on A) why I see some program output and not the rest and B) Why am I seeing any at all?
Grep for "puts" or other code that writes to stdout in your app or test code. Something is leaking data to stdout.
It looks like your view template is sending the content to stdout as well as the view:
<%= p str %>
The p function sends the string to stdout and then returns the string. The <%= ERB directive injects the value into the page being rendered, so you were both printing it out to stdout/console and rendering it in the page. This caused it to appear on the console when you were running tests.

Resources