Archive

Archive for the ‘Ruby Rails’ Category

undefined method `manage_gems’ for Gem:Module (NoMethodError)

March 16, 2010 5 comments

OK,  if you are looking for a solution to the above error hopefully this post might help you.  This happens normally if you upgrade your gems.

(Please note – I’m talking about ubuntu here, If you are on  windows then try Ubuntu :D)

Then ruby gems will create a new file called ‘gem1.8’ and it will conflict with your older ‘gem’ file. You can find both these files in /usr/bin

So when ever you say gem list (or something with gem) it gives the error ‘/usr/bin/gem:11: undefined method `manage_gems’ for Gem:Module (NoMethodError)’

As a workaround ,  I have done following and it worked for me. My solution was to create a symbolic between ‘gem’ file and ‘gem1.8’ file.

Here’s how I did it,

first copy your ‘gem’ file (as a backup)

cp /usr/bin/gem /<my other path>/

Now delete the ‘gem’ file

sudo rm -f /usr/bin/gem

OK, now create the symbolic link

ln -s /usr/bin/gem1.8 /usr/bin/gem

Thats it, now time something like

gem list and it should work.

Hope this quick note will help 😀

Advertisements

render :action and passing parameters

November 9, 2009 Leave a comment

in rails, I think most of you have come across with render action (Ex: render :action => “index” etc..). And have you ever wanted to render an action which expect some parameters ?!. OK.. Let me be clear, I have following controller actions

 

def new

@project = Project.find(params[:project_id])

end

— here my new action is expecting a parameter called project_id to load a project. And in down deep in my controller I have a create method. There I’m going to save a user object for a given project.  I want it to save with out a problem and if so it will redirect to root url and if not it should render the new action again (with error messages).

 

def create

if @user.save

#if user object successfully saved then redirect

redirect_to root_url

else

#but if saving failed then redirect beck to new action.

render :action => ‘index’,  :params => { :project_id => <project id> }

end

end

But this render action fails. Problem is even though we pass the parameters rails actually dont run the action method again (http://dev.rubyonrails.org/ticket/11037), so your parameters will not be used anyware.

Is there any alternative ?

Yes, there are many, and one would be loading the required objects before render the action again. So as per my example it should adjust like,

 

def create

if @user.save

#if user object successfully saved then redirect

redirect_to root_url

else

#lets load the project object before rendering the action

@project = Project.find(<project id>)

render :action => ‘index’

end

end

 

this would do the trick ,  Hope this helps..  🙂

 

 

 

 

 

 

 

 

 

Categories: Ruby Rails Tags:

New ruby-rails user group in Sri Lanka

September 3, 2009 Leave a comment

Hi All,

Today we have created a new user group for ruby-rails in Sri lanka – You can fined if here

http://groups.google.com/group/rubyologists

twitter -> http://twitter.com/rubyologists

Main motivation behind this is to spread the ruby language  among sri lankan developers and make the awareness.. Another main thing we would like to achieve is to share our knowledge through  monthly meetings..

Almost anybody can join and all are welcome…

Hope this will be a good start for all of us 🙂


Categories: Ruby Rails Tags:

Passing parameters to a partial

August 19, 2009 2 comments

Hi,

This is just a quick post about how to pass parameters to rails partials. (As most of you all know, partials are lightweight than components) and personally I’m using it in my project as headers and footers.

But if we are to pass some parameters to the partial how to do that ?? its simple as this

render :partial => “<partial name>”, :locals => { :param1 => “value”}

<partial name> – name of your partial (Ex /partials/footer)

:params1 – parameter name

“value” – value

Its quick and simple 🙂


Categories: Ruby Rails Tags: , ,

render_component plugin and rails 2.3

August 7, 2009 5 comments

OK, since Rails 2.3 has depriciated the render_component method and advising to use a plugin for that I went and downloaded the plugin from

http://github.com/rails/render_component/tree/master but ended up being getting this error..

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/module/aliasing.rb:33:in `alias_method’: undefined method `set_session_options’ for class `ActionController::Base’ (NameError)

🙂

Ok… Now what… After doing some googling finally I found a fix to that…. Use this git

script/plugin install 
git://github.com/lackac/render_component.git -r rails-edge 

and that fixed my issue... hope yours as well :)

and thanks for this link —

http://www.42.mach7x.com/2009/06/24/undefined-method-render_component-with-activescaffold-and-rails-2-3-2/