various tech ramblings

Rails 3.1 Error Messages and Solutions

Permalink Dec 06, 2011 01:30, by admin, Categories: Programming, Rails

Sometimes the errors are obvious but you don't see them right away, so these are here to remind me and see if I get many more. Here goes:

  1. 'merge' error

'merge' error
Was getting this:

ActionView::Template::Error (undefined method `merge' for "Convert Cap":String)

This was in a _form.html.erb view file and I had mistakenly added a label heading to the field tag instead of the label tag. Rails was trying to figure out what I was doing. Me too.

Code:

# Error causing code
<dt><%= f.label :cap %></dt>
<dd><%= f.number_field :cap, "Convert Cap" %></dd>

Code:

# Correct code
<dt><%= f.label :cap, "Convert Cap" %></dt>
<dd><%= f.number_field :cap %></dd>

Git: local, remote, Github, fast-forward, master, origin... oh my!

Permalink Nov 19, 2011 00:14, by admin, Categories: Programming

Git is distributed, so typically you have both a local and remote branch. Here is the terminology:

  • origin - the remote repository (ie like github)
  • local - the repository on your pc
  • master - the branch name on both origin & local
  • origin/master - branch name on local pc pointing to remote (origin) master

The local repository will have many pointers to it. Your local development will have a

  • master pointer to where you are locally
  • origin/master where the origin master points to.
  • heroku/master where heroku is pointing (if you use that)

Again, these all point to the same code base on your local machine. There is the same code base also on Github, because Git is distributed.

When a change is done remotely, you bring that code to your local repository by issuing the command:

Code:

$ git fetch origin


Now on your local machine your master branch still points to the original location (in local repository), but the origin/master branch now points to the updated code (also in your repository). When you issue a "git status" you will see a message like:

Your branch is behind 'origin/master' by 1 commit,
and can be fast-forwarded.

You don't need to commit anything to the repository, but you need to get the local master branch pointing to the updated code that origin/master is pointing to. Do this by:

Code:

$ git merge origin/master


This in essence is doing a "fast-forward".

If you had made changes that were committed but had not pushed to origin and you had grabbed from origin, after the above merge (and resolved conflicts, if any) then you would need to issue:

Code:

$ git push origin


to copy your changes to origin so that all is in sync again.
Tada!

New Rails Installation on Ubuntu and First Project Errors - Errno::EACCES & Rails "help" on "new" command

Permalink Jul 02, 2011 19:25, by admin, Categories: Programming, Rails

Have a new VirtualBox ubuntu image and needed to get RoR up and running. A few problems to overcome, maybe this will help someone. Probably me.

rob:~$ gem install rails
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/rob/.gem/specs

rob~$ sudo mkdir ~/.gem/specs
rob~$ gem install rails
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/rob/.gem/specs/rubygems.org%80

rob~$ sudo chmod 777 ~/.gem/specs
rob~$ gem install rails
...goodness happens...

Now to create a test application, but the "rails new sometest" command not working I continually get the "--help" displayed. This has bit me a few times earlier, so had to figure this out. I'd recently added and removed a number of gems and simply issuing:

gem cleanup

did the trick. Onward.

Rails 3: Error message: ActionView::Template::Error (undefined method `model_name' for NilClass:Class):

Permalink Mar 17, 2011 19:10, by admin, Categories: Rails, GAE

Took a little while to track this down, mostly this is a note to self. I was getting the error:

ActionView::Template::Error (undefined method `model_name' for NilClass:Class):


I was using partials and thought there was an error somewhere there. Turns out I had an end statement in my controller in the wrong place - but the right number for the *whole* controller. Thats why I was getting that mysterious undefined method `model_name' message. WTF was "model_name" ?

Rails seeds.rb not loading value into SQL table

Permalink Mar 17, 2011 19:05, by admin, Categories: Programming, Rails

Took a while to figure this out, I had a seeds.rb file and one value would not update the column in the SQL table.

#seeds.rb
:somevalue => 'some thing'

Finally figured out that I had to have attr_accessible set!

#SomeModel.rb
attr_accessible :somevalue

But what is going on?

I had added attr_accessible but not sure why. Now I do. There is a good explanation about it. Another great resource is to watch the railscast.

I had been using attr_accessible but did not realize that once you start using it, only attributes that are listed with it will be able to be mass assigned like:

User.create(:email => 'rob@rtfm....

All others will have to be assigned by direct assignment:

User.admin=true

So when loading seed data from seeds.rb, you are mass assigning. Any attributes that you assign that are not listed by attr_accessible will not be assigned.

:: Next >>

February 2012
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        
things that are of a technical nature that i find interesting and find time to write about

Search

Robs Fav Links

Places I like to visit:
powered by b2evolution free blog software