Search Results

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

Page 99/378 | < Previous Page | 95 96 97 98 99 100 101 102 103 104 105 106  | Next Page >

  • Rails route, show all elements on the same page

    - by Igor Oliveira Antonio
    I need to show all my elements on the same page. In routes: namespace :nourishment do resources :diets do resources :nourishment_meals, :controller => 'meals' get 'nourishment_meals/show_all_meals' => 'meals#show_all_meals', as: "show_all_meals" end end which will generate: nourishment_diet_nourishment_meals_path GET /nourishment/diets/:diet_id/nourishment_meals(.:format) nourishment/meals#index POST /nourishment/diets/:diet_id/nourishment_meals(.:format) nourishment/meals#create new_nourishment_diet_nourishment_meal_path GET /nourishment/diets/:diet_id/nourishment_meals/new(.:format) nourishment/meals#new edit_nourishment_diet_nourishment_meal_path GET /nourishment/diets/:diet_id/nourishment_meals/:id/edit(.:format) nourishment/meals#edit nourishment_diet_nourishment_meal_path GET /nourishment/diets/:diet_id/nourishment_meals/:id(.:format) nourishment/meals#show PATCH /nourishment/diets/:diet_id/nourishment_meals/:id(.:format) nourishment/meals#update PUT /nourishment/diets/:diet_id/nourishment_meals/:id(.:format) nourishment/meals#update DELETE /nourishment/diets/:diet_id/nourishment_meals/:id(.:format) nourishment/meals#destroy [**THIS**] nourishment_diet_show_all_meals_path GET /nourishment/diets/:diet_id/nourishment_meals/show_all_meals(.:format) nourishment/meals#show_all_meals The problem, when I do this: <%= link_to "Show all meals", nourishment_diet_show_all_meals_path, :class=>"button green" %> This error raise: Problem: Document(s) not found for class NourishmentMeal with id(s) show_all. Summary: When calling NourishmentMeal.find with an id or array of ids, each parameter must match a document Can someone help me?

    Read the article

  • rails Creating a model instance automatically when another is created

    - by bob
    Hello I have a user model and a ratings model. Whenever a new user is created I want to create a new feedback model with it automatically. Each user model has one feedback model and each feedback model has many ratings. My Classes class User < ActiveRecord::Base end class Feedback < ActiveRecord::Base belongs_to :user has_many :ratings end class Rating < ActiveRecord::Base belongs_to :feedback end My database tables -user doesn't have anything special -feedback has user_id. This user_id should be the same as the user that has just been created. For example, user_id of 1 is created, then a feedback model should be created that belongs to user_id of 1. So the user_id column in the feedback database will also be 1. - Rating has a feedback_id and a user_id the user_id in this case is the id of the person who submitted the rating. I am having it assigned through the build command. I believe my process is correct here. The Goal The goal is to have each user have a feedback table that has many ratings from other users. So if someone goes to the feedback page, they will see all the ratings given and by who. Is there a better way to approach this? How do you create a model of feedback with the same id as the user being created right when a new user is created. The idea is that when a user is created a feedback is created associated with that user so people can then go to http://localhost:3000/users/1/feedback/ and submit new ratings. I'm trying to bypass having a user rate another user with just a ratings model because I'm not sure how to do it.

    Read the article

  • ruby on rails-Problem with the selection form helper

    - by winter sun
    Hello I have a form in witch users can add their working hours view them and edit them (All in one page). When adding working hours the user must select a project from a dropdown list. In case the action is adding a new hour record the dropdown field should remain empty (not selected) in case the action is edit the dropdown field should be selected with the appropriate value. In order to overcome this challenge I wrote the following code <% if params[:id].blank?%> <select name="hour[project_id]" id="hour_project_id"> <option value="nil">Select Project</option> <% @projects.each do|project|%> <option value="<%=project.id %>"><%=project.name%></option> <% end%> </select> <% else %> <%= select('hour','project_id', @projects.collect{|project|[project.name,project.id]},{:prompt => 'Select Project'})%> <% end %> So in case of save action I did the dropdown list only with html, and in case of edit action I did it with the collect method. It works fine until I tried to code the errors. The problem is that when I use the error method: validates_presence_of :project_id it didn't recognize it in the html form of the dropdown list and don’t display the error message (its working only for the dropdown with the collect method). I will deeply appreciate your instructions and help in this matter

    Read the article

  • Generic Rails Route Representation?

    - by Flemish Bee Cycle
    Given one or more instances of a model (AR or DM, whatever). Is it possible to generate the route in the requirement form, by which I mean "/foos/:id" Given the route: resource :foo do resource :bar end generate_route_method [@foo,@bar] - "/foos/:id/bars/:id" I'm not talking about #foos_path or #polymorphic_path, rather, literally generating the string containing the wildcard components (i.e ":id"), the same as it would appear as if you did "rake routes".

    Read the article

  • rails update whole index of a model with one click

    - by mattherick
    hello! i have a store model, this will handle my leaflet and my shoppingcart for my shop. now i d´like to show all items added from an user to his leaflet in the index of store. in the store an user can change the quantity of the choosen items. and now i want to save that the changes of the different quantities in the database with one click on a button "update store". so how could i implement an update over the whole index with one click? i´d like to do this with ajax and most dynamically. somebody has an idea? i render all items into a form so far, but now i have the problem, when i submit this form only the last quantity and item id are included in the params. further i pushed every quantity into an array and i want to submit this also as a param. but i could not. please give me some tips, will be very fine :) mattherick

    Read the article

  • Rails running multiple delayed_job - lock tables

    - by pepernik
    Hey. I use delayed_job for background processing. I have 8 CPU server, MySQL and I start 7 delayed_job processes RAILS_ENV=production script/delayed_job -n 7 start Q1: I'm wondering is it possible that 2 or more delayed_job processes start processing the same process (the same record-row in the database delayed_jobs). I checked the code of the delayed_job plugin but can not find the lock directive in a way it should be. I think each process should lock the database table before executing an UPDATE on lock_by column. They lock the record simply by updating the locked_by field (UPDATE delayed_jobs SET locked_by...). Is that really enough? No locking needed? Why? I know that UPDATE has higher priority than SELECT but I think this does not have the effect in this case. My understanding of the multy-threaded situation is: Process1: Get waiting job X. [OK] Process2: Get waiting jobs X. [OK] Process1: Update locked_by field. [OK] Process2: Update locked_by field. [OK] Process1: Get waiting job X. [Already processed] Process2: Get waiting jobs X. [Already processed] I think in some cases more jobs can get the same information and can start processing the same process. Q2: Is 7 delayed_jobs a good number for 8CPU server? Why yes/not. Thx 10x!

    Read the article

  • Rails creating a new session every page view

    - by danhere
    Hi everyone, I'm following the Agile RoR book somewhat to apply it to a project for school. It's going good until I get to sessions. I continually get Authenticity Invalid Tokens and when I look at my sessions table in the database, there's a new session being created every time I refresh the page. Is that right or is something messed up? Thanks.

    Read the article

  • Rails acts_as_taggable_on grouped alphabetically?

    - by Ray Dookie
    Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase <= y.name.downcase } what is the easiest/most efficient way to display the tags in my view grouped by letters? i.e A - "Alpha", "Apple", "Aza" B - "Beta", "Bonkers" . . . Z - "Zeta", "Zimmer" Any ideas?

    Read the article

  • Rails: three most recent comments for unique users

    - by Dennis Collective
    class User has_many :comments end class Comment belongs_to :user named_scope :recent, :order => 'comments.created_at DESC' named_scope :limit, lambda { |limit| {:limit => limit}} named_scope :by_unique_users end what would I put in the :by_unique_users so that I can do Comment.recent.by_unique_users.limit(3), and only get one comment per user

    Read the article

  • Ruby on Rails: How to use a local variable in a collection_select

    - by mmacaulay
    I have a partial view which I'm passing a local variable into: <%= render :partial => "products/product_row", :locals => { :product => product } %> These are rows in a table, and I want to have a <select> in each row for product categories: <%= collection_select(:product, :category_id, @current_user.categories, :id, :name, options = {:prompt => "-- Select a category --"}, html_options = { :id => "", :class => "product_category" }) %> (Note: the id = "" is there because collection_select tries to give all these select elements the same id.) The problem is that I want to have product.category be selected by default and this doesn't work unless I have an instance variable @product. I can't do this in the controller because this is a collection of products. One way I was able to get around this was to have this line just before the collection_select: <% @product = product %> But this seems very hacky and would be a problem if I ever wanted to have an actual instance variable @product in the controller. I guess one workaround would be to name this instance variable something more specific like @product_select_tmp in hopes of not interfering with anything that might be declared in the controller. This still seems very hacky though, and I'd prefer a cleaner solution. Surely there must be a way to have collection_select use a local variable instead of an instance variable. Note that I've tried a few different ways of calling collection_select with no success: <%= collection_select(product, ... <%= collection_select('product', ... etc. Any help greatly appreciated!

    Read the article

  • Rails with passenger only runs in development

    - by Ignace
    Hey, I have a problem on one of our webservers. I'll try to explain it as clear as possible, but I'm not 100% aware of all the configuration of the server. There are 2 sites running next to eachother (blcc_preprod and blcc_prod), so in the 'sites-enabled' of apache this i have a file 'blcc' like this: <VirtualHost *:80> DocumentRoot /opt/dn/blcc/www RailsBaseURI /blcc_preprod RailsBaseURI /blcc_prod RailsEnv production </VirtualHost> My config/environments/production.log (from both) looks like this(I removed all comments, because it messes with the layout) config.cache_classes = true config.action_controller.consider_all_requests_local = false config.action_controller.perform_caching = true config.action_view.cache_template_loading = true config.log_level = :debug The weird thing is, that my production log dates from months ago, so something is really wrong. Could someone help? If you need more info, just ask. Thanks! Edit: Error.log from apache show the normal output for a event to the server (the situation here is that the webserver plugs in to another business (java) server via a framework) Access.log is empty Content from other_vhosts_access.log after we surf to ip/blcc_preprod is the following blcc.localdomain:80 192.168.21.194 - - [25/May/2010:08:33:04 +0200] "GET/ blcc_preprod HTTP/1.1" 500 594 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"

    Read the article

  • How do I create a web service with rails?

    - by NotDan
    I have a silverlight application that needs to talk to a rails app to add a record. I have been able to get the silverlight app to successfully do the POST assuming everything goes good. Now, however, I need to be able to make it more robust and have the rails app return error/success messages to the silverlight app in a format it can read (xml maybe?). I can modify the rails app and silverlight app as needed. What is the best way to accomplish this with rails?

    Read the article

  • Rails: print associations in ActiveRecord inspectors

    - by marienbad
    When I print an ActiveRecord of a Department, I get: Department:0x210ec4c { :id = 3, :name = "Computer Science", ... :school_id = 3 } How can I make it give me the School instead of the School_ID? In other words, call to_s on the school found by the school_id. Just like how when I have a Department d, I can say d.school

    Read the article

  • Rails. Putting update logic in your migrations

    - by Daniel Abrahamsson
    A couple of times I've been in the situation where I've wanted to refactor the design of some model and have ended up putting update logic in migrations. However, as far as I've understood, this is not good practice (especially since you are encouraged to use your schema file for deployment, and not your migrations). How do you deal with these kind of problems? To clearify what I mean, say I have a User model. Since I thought there would only be two kinds of users, namely a "normal" user and an administrator, I chose to use a simple boolean field telling whether the user was an adminstrator or not. However, after I while I figured I needed some third kind of user, perhaps a moderator or something similar. In this case I add a UserType model (and the corresponding migration), and a second migration for removing the "admin" flag from the user table. And here comes the problem. In the "add_user_type_to_users" migration I have to map the admin flag value to a user type. Additionally, in order to do this, the user types have to exist, meaning I can not use the seeds file, but rather create the user types in the migration (also considered bad practice). Here comes some fictional code representing the situation: class CreateUserTypes < ActiveRecord::Migration def self.up create_table :user_types do |t| t.string :name, :nil => false, :unique => true end #Create basic types (can not put in seed, because of future migration dependency) UserType.create!(:name => "BASIC") UserType.create!(:name => "MODERATOR") UserType.create!(:name => "ADMINISTRATOR") end def self.down drop_table :user_types end end class AddTypeIdToUsers < ActiveRecord::Migration def self.up add_column :users, :type_id, :integer #Determine type via the admin flag basic = UserType.find_by_name("BASIC") admin = UserType.find_by_name("ADMINISTRATOR") User.all.each {|u| u.update_attribute(:type_id, (u.admin?) ? admin.id : basic.id)} #Remove the admin flag remove_column :users, :admin #Add foreign key execute "alter table users add constraint fk_user_type_id foreign key (type_id) references user_types (id)" end def self.down #Re-add the admin flag add_column :users, :admin, :boolean, :default => false #Reset the admin flag (this is the problematic update code) admin = UserType.find_by_name("ADMINISTRATOR") execute "update users set admin=true where type_id=#{admin.id}" #Remove foreign key constraint execute "alter table users drop foreign key fk_user_type_id" #Drop the type_id column remove_column :users, :type_id end end As you can see there are two problematic parts. First the row creation part in the first model, which is necessary if I would like to run all migrations in a row, then the "update" part in the second migration that maps the "admin" column to the "type_id" column. Any advice?

    Read the article

  • Recalculate Counter Cache of 120k Records [Rails / ActiveRecord]

    - by Sebastian
    The following situation: I have a poi model, which has many pictures (1:n). I want to recalculate the counter_cache column, because the values are inconsistent. I've tried to iterate within ruby over each record, but this takes much too long and quits sometimes with some "segmentation fault" bugs. So i wonder, if its possible to do this with a raw sql query?

    Read the article

  • Rails routing/polymorphism issue - how to model the following

    - by 46and2
    Hi all, I have an app where a 'user' belong to a 'client' or a 'vendor' (and client and vendor has_many users). In the admin namespace, I want to administer these users - so an admin would choose a client or a vendor, then nav to that client's or vendor's users. My question is, short of making the user model polymorphic, how could I model/route this? Here is what I have in terms of routing: map.namespace :admin do |admin| admin.resources :clients admin.resources :vendors end I know I could do something like: map.namespace :admin do |admin| admin.resources :clients do |client| client.resources :users admin.resources :vendors do |vendor| vendor.resources :users end end But the above would definitely need me to treat the User as polymorphic. I'm just wondering what you would recommend or what my options are. Thanks.

    Read the article

  • Rails CSV import, adding to a related table

    - by Jack
    Hi, I have a csv importing system on my app (used locally only) which parses the csv file line by line and adds the data to the database table. This is based on a tutorial here. require 'csv' def csv_import @parsed_file=CSV::Reader.parse(params[:dump][:file]) n = 0 @parsed_file.each_with_index do |row, i| next if i == 0 #ignore the first row course = Course.new course.title = row[0] course.unit_code = row[1] course.course_type = row[2] course.value = row[3] course.pass_mark = row[4] if course.save n = n+1 GC.start if n%50==0 end flash.now[:message] = "CSV Import Successful, #{n} new courses added to the database." end redirect_to(courses_url) end This is all in the courses controller and works fine. There is a relationship that courses HABTM years and years HABTM courses. In the csv file (effectively in row[5] to row[8]) are the year_id s. Is there a way that I can add this within the method above. I am confused as to how to loop over the 4 items and add them to the courses_years table. Thank you Jack

    Read the article

  • Best way to create a preview functionality in rails

    - by slythic
    Hi all, I'm looking to implement a preview functionality in my posts scaffold. All I need to do is allow a user to enter information in the new view (/posts/new) and then replace the submit button with a preview button. Once the preview button is clicked, the user is routed to the preview page (probably /posts/new/preview). If the user wants to make a change they would click 'go back' or if they are happy with the post they can then submit the post. I found this article (http://eyedeal.team88.org/node/105) but it seems dated. Any ideas on what the best approach for this would be? Many thanks, Tony

    Read the article

  • Dynamic "OR" conditions in Rails 3

    - by Ryan Foster
    I am working on a carpool application where people can search for lifts. They should be able to select the city from which they would liked to be picked up and choose a radius which will then add the cities in range to the query. However the way it is so far is that i can only chain a bunch of "AND" conditions together where it would be right to say "WHERE start_city = city_from OR start_city = a_city_in_range OR start_city = another_city_in_range" Does anyone know how to achive this? Thanks very much in advance. class Search < ActiveRecord::Base def find_lifts scope = Lift.where('city_from_id = ?', self.city_from) #returns id of cities which are in range of given radius @cities_in_range_from = City.location_ids_in_range(self.city_from, self.radius_from) #adds where condition based on cities in range for city in @cities_in_range_from scope = scope.where('city_from_id = ?', city) #something like scope.or('city_from_id = ?', city) would be nice.. end end

    Read the article

  • rails, rest, render different action with responds to

    - by Sam
    Maybe my logic is not restful or know if this is how you would do it but this is what I am trying to do. I'm getting a category inside a category controller and then once I get that category I want to return to an index page in a different controller but keep that @category and the Category.busineses. Before rest I would have just done this: render :controller = "businesses" and it would have rendered the view of the index action in that controller. now in my respond_to block I have this format.html {redirect_to(business_path)} # index.html.erb format.xml { render :xml => @businesses } but of course with a render it looses the instance variable and starts with a new action. So what I want to do is render the action instead of redirecting to that action. is this possible?

    Read the article

  • Rails problem find by sql

    - by Totty
    I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM \' SELECT * FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY i.updated_at LIMIT ?, 6\ '; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit;') 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 'SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit' at line 1: PREPARE stmt FROM ' SELECT * FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY i.updated_at LIMIT ?, 6'; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit;

    Read the article

  • How to unescape String in Rails

    - by Midday
    I have a long String from a WYSIWYG (in my case YUI) which I then send as html email. since its an email all CSS needs to be inline so how should i unescape this: <span style=\"color: #c00000; font-size: 14px;\"> Is .gsub '\"' , '"' enough?

    Read the article

  • Rails relation select

    - by Dimitar Vouldjeff
    Hi, I have the following models: class User < ActiveRecord::Base has_many :results, :dependent => :destroy has_many :participants, :dependent => :destroy has_many :courses, :through => :participants end class Course < ActiveRecord::Base has_many :tests, :dependent => :destroy has_many :participants, :dependent => :destroy has_many :users, :through => :participants end class Result < ActiveRecord::Base belongs_to :test belongs_to :user end class Test < ActiveRecord::Base belongs_to :course has_many :results, :dependent => :destroy end The Idea is that a user has_and_belongs_to_many courses, the course has_many tests, and every test has_and_belongs_to_many users (results). So what is the best query to select every Result from a single Course (not test), and also the query to select every Result from a single Course, but from one user. Thanks!

    Read the article

< Previous Page | 95 96 97 98 99 100 101 102 103 104 105 106  | Next Page >