Search Results

Search found 9437 results on 378 pages for 'rails newbie'.

Page 105/378 | < Previous Page | 101 102 103 104 105 106 107 108 109 110 111 112  | Next Page >

  • Body class for controller in Rails app.

    - by Vincent
    Currently I have this in my layout: <body class="<%= controller.controller_name %>"> I want to add an additional class that will be the same for all actions in any controller where it's set, something like: class SomeController < ApplicationController body_class 'page' ... end class AnotherController < ApplicationController body_class 'page' ... end Which will result in: <body class="some page"> <body class="another page"> What would be the easiest way to achieve this? Can I use controller class variables for this?

    Read the article

  • Execute script with Ruby on Rails?

    - by yuval
    I want to start my daemon with my application. In the command line, I can write something like lib/daemons/mydaemon_ctl start to start up my daemon, but I have to do this manually. I want the daemon to start when I start my server (i.e. when the initializer files are loaded). Is there a ruby command for executing a command line? Something like exec "lib/daemons/mydaemon_ctl start"? Thanks!

    Read the article

  • rails include with options

    - by holden
    Is it possible to limit an AR :include to say only pull in one record... Item.find(:all, :include => [ :external_ratings, :photos => LIMIT 1 ]) I have a list of items and each item has between 5 and 15 photos. I want to load a photo id into memory, but i don't need all of them, I just want to preview the first one. Is there a way to do this?

    Read the article

  • Rails page caching and flash messages

    - by KJF
    I'm pretty sure I can page cache the vast majority of my site but the one thing preventing me from doing so is that my flash messages will not show, or they'll show at the wrong time. One thing I'm considering is writing the flash message to a cookie, reading it and displaying it via javascript and clearing the cookie once the message has been displayed. Has anyone had any success doing this or are there better methods? Thanks.

    Read the article

  • rails delete_all exception

    - by Sergei
    Hello, guys! I have some User model, Role model and Assignment model to manage role-based user system. Just like here . So, here some kind of code, to include roles into users form: <% for role in Role.all %> <%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role) %> <%=h role.name %><br /> <% end %> And all's working fine for new records and for editing records. But I just want to make possible to restrict deleting Assigment with id=1, cause this Assignment for default root user from migration, who must be admin anyway. Otherwise, I can lose my last admin. So I've tryed to add before_destroy to Assignment.rb model, but it doesn't work. I've noticed, that when I'm editing user and trying to remove his admin role(assignment), the server makes a delete_all method, not destroy method. So, does anybody know how to catch the deleting of Assignment with id=1 through this kind of code? Thanks in advance!

    Read the article

  • Is it possible to send an automated email with dynamic content in Rails

    - by Danny McClelland
    Hi Everyone, I am looking into the best way of doing the following: I have a model called Kase, and when a user creates a new case then are taken to the show view as you would expect. I am trying to work out what the best way of sending an automated email between those two events is. I would need to include in the email the content of a couple of the fields, ideally I am looking for a way of just typing out the email and adding the same snippets that are in the show view for each of the fields I need. I am using the Base App from Github so the email sending is already setup for the user authentication and registration, but I'm not sure where to begin. The reason I want to send the email is to create a new Case in our Highrise account, and I don't have a clue how to use the API. So I think the email sending is the easier way. Thanks, Danny

    Read the article

  • Catching an error for a child resource in Ruby on Rails

    - by randombits
    What is the best way to add errors to render if a child resource is really what's having issues and not the parent resource? In english what I mean is the following.. imagine the following code: @foo = Foo.new foochild = Foochild.new // break foochild somehow @foo << foochild @foo.save now when I do: format.xml { render :xml => @foo.errors } I don't get anything about how foochild broke, meaning the error message is useless to the user. How does one go about fixing this?

    Read the article

  • Ruby on Rails controller-view refactoring

    - by Dimitar Vouldjeff
    Hello, In my app I am using the ym4r-gm plugin, which allows you to play with the Google Maps API... I put the map "setup" in the controller: @map = GMap.new("div_map") @map.control_init(:large_map => true, :map_type => true) @map.center_zoom_init([47.0, 26.0], 7) ... And only render @map in the view. So my first question is whether I am using the right approach of "diving" this code? And the second question is: I have to models, which are rendering the same map (only the resources are different). Where should I put my refactored method that renders the map? In the application controller, maybe? Thanks in advance, I hope you will understand me!

    Read the article

  • Rails: using find method to access joined tables for polymorphic relationships

    - by DJTripleThreat
    Ok, I have a generic TimeSlot model that deals with a start_at and an end_at for time spans. A couple models derive from this but I'm referring to one in this question: AppointmentBlock which is a collection of Appointments. I want to validate an AppointmentBlock such that no other AppointmentBlocks have been scheduled for a particular Employee in the same time frame. Since AppointmentBlock has a polymorphic association with TimeSlot, you have to access the AppointmentBlock's start_at and end_at through the TimeSlot like so: appt_block.time_slot.start_at This means that I need to have some kind of join in my :conditions for my find() method call. Here is my code so far: #inside my appointment_block.rb model validate :employee_not_double_booked def employee_not_double_booked unless self.employee_id # this find's condition is incorrect because I need to join time_slots to get access # to start_at and end_at. How can I do this? blocks = AppointmentBlock.find(:first, :conditions => ['employee_id = ? and (start_at between ? and ? or end_at between ? and ?)', self.employee_id, self.time_slot.start_at, self.time_slot.end_at, self.time_slot.start_at, self.time_slot.end_at]) # pseudo code: # collect a list of appointment blocks that end after this # apointment block starts or start before this appointment # block ends that are also associated with this appointment # blocks assigned employee # if the count is great then 0 the employee has been double # booked. # if a block was found that means this employee is getting # double booked so raise an error errors.add "AppointmentBlock", "has already been scheduled during this time" if blocks end end Since AppointmentBlock doesn't have a start_at or an end_at how can I join with the time_slots table to get those conditions to work?

    Read the article

  • rails error on create action

    - by ash34
    SQL (2.0ms) SELECT task_report_requests_seq.NEXTVAL id FROM dual TaskReportRequest Create (2.2ms) INSERT INTO task_report_requests (location, created_at, updated_at, id, freq, login, task_dt) VALUES('020', TO_DATE('2010-05-25 05:02:38','YYYY-MM-DD HH24:MI:SS'), TO_DATE('2010-05-25 05:02:38','YYYY-MM-DD HH24:MI:SS'), 10023, 'M', NULL, TO_DATE('2010-05-30 00:00:00','YYYY-MM-DD HH24:MI:SS')) NoMethodError (You have a nil object when you didn't expect it! The error occurred while evaluating nil.call): app/controllers/task_report_requests_controller.rb:45:in `create' It says error evaluating nil.call . Can someone tell me when I would get such an error. I am not able to figure out with this information. thanks, ash

    Read the article

  • Rails - Why is HAML showing the full hash?

    - by Mr. Demetrius Michael
    View: !!! %html %head %title= full_title(yield(:title)) =stylesheet_link_tag "application", media: "all" =javascript_include_tag "application" =csrf_meta_tags =render 'layouts/shim' %body =render 'layouts/header' .container =flash.each do |key, value| %div{class: "alert alert-#{key}"} #{value} Controller def create @user = User.new(params[:user]) if @user.save flash[:success] = "This is Correct" redirect_to @user else flash[:wrong] = "no" render 'new' end end Regardless of the flash (:success or :wrong or otherwise) it always compiles the entire hash as html (below) Output: <!DOCTYPE html> .... <div class='container'> <div class='alert alert-wrong'>no</div> {:wrong=&gt;&quot;no&quot;} </div> </body> </html> I have no idea why {:wrong=&gt;&quot;no&quot;} is being displayed. I've been staring at this terminal for hours. What's interesting is that the hash is being outputted with the container id, but not in the alert class. It feels like an indentation problem, but I went through several permutations with no success.

    Read the article

  • Only show non blank attributes for a model in views in Rails

    - by Senthil
    Say I've a user model and there are bunch of user info, like email, birthdate, location, telephone number etc. What's the simplest way of hiding the attributes that are blank? I've doing something like <% if blog.title.empty? -%> <p>Body: <%=h blog.body %></p> <p>Comments: <%=h blog.comments %></p> <% elsif blog.body.empty? %> <p>Title: <%=h blog.title %></p> <p>Comments: <%=h blog.comments %></p> <% else -%> <p>Title: <%=h blog.title %></p> <p>Body: <%=h blog.body %></p> <% end -%> Clearly that is one ugly child. Other than using partials to render, is there a trick to only show non blank fields? I've been trying to write a helpher method to make the view cleaner, but that's even more ugly. Any help is appreciated.

    Read the article

  • Rails Seed confusion

    - by sscirrus
    I'm having trouble seeding my database using seed.rb, specifically where table relationships are concerned. Here's a sample of the code: # seed.rb user = User.find_or_create_by_login( :login => "myname", :email => "[email protected]", :user_type => "Admin", :password => "admin", :password_confirmation => "admin") project = Project.find_or_create_by_user_id( :user_id => user.id, :name => "Test Project") When project is created (along with other unrelated parameters I've left out from above), user_id is empty. How can I get this to work?

    Read the article

  • How do I REALLY get started programming in Ruby on Rails

    - by Nate
    I can't figure out where exactly to go in order to write the Ruby code itself. I know that I can enter things line-by-line in Terminal (I'm on a Mac), but I'd like to figure out how to start using something like Xdrive (Apple won't allow me to download Xrive because I have OS X 10.5, not 10.6). What steps do I need to take in order to start writing code in a program like xDrive. Thank you in advance.

    Read the article

  • .save puts NULL in id field in Rails

    - by mathee
    Here's the model file: class ProfileTag < ActiveRecord::Base def self.create_or_update(options = {}) id = options.delete(:id) record = find_by_id(id) || new record.id = id record.attributes = options puts "record.profile_id is" puts record.profile_id record.save! record end end This gives me the correct print out in my log. But it also says that there's a call to UPDATE that sets profile_id to NULL. Here's some of the output in the log file: Processing ProfilesController#update (for 127.0.0.1 at 2010-05-28 18:20:54) [PUT] Parameter: {"commit"=>"Save", ...} ?[4;36;1mProfileTag Create (0.0ms)?[0m ?[0;1mINSERT INTO `profile_tags` (`reputation_value`, `updated_at`, `tag_id`, `id`, `profile_id`, `created_at`) VALUES(0, '2010-05-29 01:20:54', 1, NULL, 4, '2010-05-29 01:20:54')?[0m ?[4;35;1mSQL (2.0ms)?[0m ?[0mCOMMIT?[0m ?[4;36;1mSQL (0.0ms)?[0m ?[0;1mBEGIN?[0m ?[4;35;1mSQL (0.0ms)?[0m ?[0mCOMMIT?[0m ?[4;36;1mProfileTag Load (0.0ms)?[0m ?[0;1mSELECT * FROM `profile_tags` WHERE (`profile_tags`.profile_id = 4) ?[0m ?[4;35;1mSQL (1.0ms)?[0m ?[0mBEGIN?[0m ?[4;36;1mProfileTag Update (0.0ms)?[0m ?[0;1mUPDATE `profile_tags` SET profile_id = NULL WHERE (profile_id = 4 AND id IN (35)) ?[0m I'm not sure I understand why the INSERT puts the value into profile_id properly, but then it sets it to NULL on an UPDATE. If you need more specifics, please let me know. I'm thinking that the save functionality does many things other than INSERTs into the database, but I don't know what I need to specify so that it will properly set profile_id.

    Read the article

  • Rails can't find my route but it exists!

    - by DJTripleThreat
    Ok I have events that I want to publish/unpublish with an extra action (nonRESTful) I watched Ryan Bates' railscast on this: http://railscasts.com/episodes/35-custom-rest-actions and it got me most of the way. I think the problem is that my route is nested in an /admin section so even though when I run rake routes and get: publish_admin_event PUT /admin/events/:id/publish(.:format) {:controller=>"event_services", :action=>"publish"} This won't work in my /views/admin/index.html.erb file: <%= link_to 'Publish', publish_admin_event(event), :method => :put %> because it claims that path doesn't exist! And neither will this: <%= link_to 'Publish', {:controller => :event_services, :action => :publish}, {:method => :put, :id => event} %> and says that "No route matches {:controller=>"event_services", :action=>"publish"}" so what gives? (And I've tried restarting my server so that isn't it.) EDIT: This DOES work: <%= link_to 'Publish', "/admin/events/" + event.id.to_s + "/publish", :method => :put %> But I'd rather NOT do this.

    Read the article

  • Rails ActiveRecord- has_many through and belongs_to a related model

    - by Nick
    I have 3 models sites, user_favorites and users. Relevant relationships: class Site < ActiveRecord::Base has_many :users, :through => :user_favorites class UserFavorite < ActiveRecord::Base belongs_to :user, :counter_cache => true belongs_to :site end class User < ActiveRecord:Base has_many :user_favorites has_many :sites, :through => :user_favorites All of that works just fine. I'd like to add a new attribute to the Site model to indicate which user created it. I don't believe this constitutes a has_and_belongs_to_many scenario. A site has many users through user_favorites but I want it to belong to a single user reflecting the owner/creator. I'm wondering what the ORM best practice is for this. SQL wise I'd just use different joins depending on what I was trying to query with a created_by FK in Site. Sorry if I'm missing something basic here. Thanks

    Read the article

  • Rails "Missing these required gems" error for installed gems

    - by Shpigford
    I know this has been asked multiple times before, but I've tried those things and still am not having any luck. For the mechanize gem, I keep getting the "Missing these required gems" error when I run db:migrate on my production server. Here's the full error: Missing these required gems: mechanize You're running: ruby 1.8.6.111 at /usr/bin/ruby1.8 rubygems 1.3.5 at /home/user/.gem/ruby/1.8, /usr/lib/ruby/gems/1.8 Output of which ruby is /usr/bin/ruby Output of which gem is /usr/bin/gem When I run gem list mechanize (1.0.0) is definitely in the list. What am I doing wrong here?

    Read the article

  • Rails has_and_belongs_to_many join across 3 tables

    - by Birdman
    I have a three models: listing, category, and site. There is a many to many relationship between listing and site and there is a many to many relationship between listing and category. A listing thus belongs to one or more sites and one or more categories (a listing can appear on multiple sites and multiple categories). Given a site id and a category id, I want a set of all the listings. I understand how to get the listings from a site id (listings = site.listings) and how to get the listings from a category id (listings = category.listings), but how do I get the triple join of the set of listings from both a site id and category id? The sql would look something like (sit_id and cat_id are input): select l.name from listings l, categories_listings cl, listings_sites, ls where cl.category_id = cat_id and ls.site_id = sit_id and cl.listing_id = l.id and ls.listing_id = l.id Thanks in advance

    Read the article

  • Ruby on Rails: Javascript: How to grob focus when the text box appears

    - by DerNalia
    So, I have <script type="text/javascript"> function grabFocus(){ document.getElementByID("category_name").focus(); } </script> <div> <h1>New category</h1> <br/> <% remote_form_for :category, @category, :url=>{:action=>'ajax_create'} do |f| %> <%= f.error_messages %> <%= f.hidden_field :object_type %> <p> <%= f.text_field :name, :label=>false %> <%= f.submit 'Create' %> </p> <% end %> <br/> </div> and before I just had the <script type="text/javascript"> document.getElementByID("category_name").focus(); </script> at the bottom of the file. but other websites suggested that I make it a function, and call it in onLoad... but the partial I'm working with (entire thing pasted above) doesn't have a body... I'm showing the partial in the iframe that facebox uses... ideas?

    Read the article

  • Rails advanced queries with join and sum calculation

    - by Dustin Brewer
    I have two models: companies and expenses. Companies have many expenses and expenses belong to companies. My expense model has an 'amount' column. I was wondering if there is a way to perform a find based on a date range and the amount column of the expenses. Something like top 3 companies by total expense amounts over a 7 day period. I've tried for the better part of the day to get this to work, I've attempted joins, chaining named scopes, raw sql, etc. and I'm not having any luck. Thanks for the help.

    Read the article

  • Rails autlogic : How to make Levels?

    - by Oluf Nielsen
    Hello, i followed this tutorial fo setting Autlogic up properly. So, my site needs a form of level, like "Admin", "Moderator", "User", "Guest". So Admins can do everything, where Moderators may not can make site changes. And Users can't destroy, Update or Create. I've have googled a bit.. But nothing found, so i thought you guys might can help me out? Thank you.

    Read the article

< Previous Page | 101 102 103 104 105 106 107 108 109 110 111 112  | Next Page >