Search Results

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

Page 76/378 | < Previous Page | 72 73 74 75 76 77 78 79 80 81 82 83  | Next Page >

  • Rails - Displaying Large Set of Data in a Table / Start new column after X rows

    - by ChrisWesAllen
    Hi, I trying to display a large set of checkboxes in my rails app and didnt knwo the syntax for displaying like 15 rows then after starting a new column. I have a model with about 120 entries. Currently, I have it being displayed in the view as.... <% for interest in Interest.find(:all) %> <%= check_box_tag Blah Blah Blah %> <%= interest.name %> <% end %> How can I make it so it makes a table and after every 15 or so rows make a new column???

    Read the article

  • Rails: Creating subfolders in model?

    - by keruilin
    I'm going to have a ton of subclasses, so want to organize them under a subfolder called stream. I added the following line to the environment.rb so that all classes in the subfolder would be loaded: Rails::Initializer.run do |config| ... config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? } ... end I thought this would solve the issue in which by convention the model class is namespaced into an according module. However, when I try to call one of the classes called stream in the stream folder, I get the following error: NoMethodError: undefined method `new' for Stream:Module from (irb):28 from /usr/local/bin/irb:12:in `<main>' Here's the model for the parent and one child: class Stream end class EventStream < Stream end Any idea what the issue is?

    Read the article

  • Rails Collection_select names

    - by Jack
    Hi, I am creating a Rails app and have added a form: <div class="field"> <%= f.label :title %><br /> <%= f.text_field :title %> </div> <div class="field"> <%= f.label :client_id %><br /> <%= collection_select(:project, :client_id, Client.all, :id, :contact_name, {:prompt => "Select a Client"}) %> </div> This currently displays the contact_name of the client. Is it possible to have it display a list of contact_names concatenated with the client_id? If so, how would I do this? Cheers

    Read the article

  • Fallback to another exiting MIME type when the required is missing in Rails

    - by fifigyuri
    I want to extend the exiting supported HTML type of my site by support for iPhone. For this I registered a new MIME type. I created a layout for iphone and also converted some of the html views to iphone version. However, I did not convert all of the html.erb-s. I do not see the reason to convert all views, some of them should not change, some partials simply just remain the same. I guess there should be a solution for this case. I tried to search for ways how to fallback to an existing format, but did not find any answer. Does a way to define fallback for MIME types in Rails exist? How does it work? If it doesn't exist and thus I wanted to solve the issue not the right way, what could simply solve the task of extending an existing site by another format? Thanks for your suggestions.

    Read the article

  • NoMethodError when trying to invoke helper method from Rails controller

    - by John Topley
    I'm getting a NoMethodError when trying to access a method defined in one of my helper modules from one of my controller classes. My Rails application uses the helper class method with the :all symbol as shown below: class ApplicationController < ActionController::Base helper :all . . end My understanding is that this should make all of my controller classes automatically include all of the helper modules within the app/helpers directory, therefore mixing in all of the methods into the controllers. Is this correct? If I explicitly include the helper module within the controller then everything works correctly.

    Read the article

  • Rails botches the SQL on a complex save

    - by Dan B
    Hi, I am doing something seemingly pretty easy, but Rails is messing up the SQL. I could just execute my own SQL, but the framework should be able to handle this. Here is the save I am trying to perform: w = WhipSenVote.find(:first, :conditions => ["whip_bill_id = ? AND whip_sen_id = ?", bill_id, k]) w.votes_no = w.votes_no - 1 w.save My generated SQL looks like this: SELECT * FROM "whip_sen_votes" WHERE (whip_bill_id = E'1' AND whip_sen_id = 7) LIMIT 1 And then: UPDATE "whip_sen_votes" SET "votes_yes" = 14, "updated_at" = '2009-11-13 19:55:54.807000' WHERE "id" = 15 The first select statement is correct, but as you can see, the Update SQL statement is pretty wrong, though the votes_yes value is correct. Any ideas? Thanks!

    Read the article

  • Rails create_table query

    - by Steve
    Hi, I am a beginner in Rails. In the following code,there is an id which is set as false. What's the meaning of it? class CreateCoursesStudents < ActiveRecord::Migration def self.up create_table :courses_students, :id => false do |t| t.integer :course_id, :null => false t.integer :student_id, :null => false end # Add index to speed up looking up the connection, and ensure # we only enrol a student into each course once add_index :courses_students, [:course_id, :student_id], :unique => true end def self.down remove_index :courses_students, :column => [:course_id, :student_id] drop_table :courses_students end end Thanks

    Read the article

  • Rails 3 loading all models on startup

    - by janechii
    Hi all, I have a class method mixed in to all my models. the method gets called when the model class is evaluated. unfortunately (for me), this seems to be on-demand, whenever the model is needed in development env. how can have rails load all the models at start up? is this even advisable? class Foo < ActiveRecord::Base include Acl register_acl # i need this to be called for all models at start up end thank you!

    Read the article

  • Rails model to represent multiple fields

    - by Tristan O'Neil
    I'm developing a rails project where I have one data model with multiple fields that are collection selects. I'd like to create another model to represent all of these collection select fields. So, for instance, my main data model has three collection select fields -- one for county, one for category, and one for classification. I could separate these into three separate data models, but that seems redundant since they all share the same characteristics. They have a type and a value, like a county is a county and it has a value of let's say Sonoma, just as category has a type of category and a value of let's say Winery. If you've ever used Drupal, I'm basically looking for the behavior of the taxonomy functionality. So you see my dilemma: I need to separate these fields into three separate fields but they have very similar data structures. Any suggestions would be greatly appreciated.

    Read the article

  • How to set a predefined value in a form in Rails

    - by marco
    So I just got started in Rails, and I'm trying to create an Object (a book_loan in my case) with a Form. The thing is that I get to this form by clicking on a book, so I pass the book_id as a parameter, like localhost:3000/loans/new?id=1. Now I don't want the user to be able to set the book id field in the form, since I already know the id. So my question is how to set the value in the form. I have been trying things like: <% form_for(@loan) do |f| %> <%= f.error_messages %> ... <%= @loan.book_id = params[:id] %> <%= f.submit 'Create' %> <% end %> without any success. Does anybody have a hint for me?

    Read the article

  • simple search in rails

    - by Adnan
    Hi, I'm making a simple search form in rails. In my search view I have two select boxes with fixed values like: SELECT BOX 1 SELECT BOX 2 ALL, ALL, FR, FR, US, US, DE DE And I have 2 fields in my DB with country_from and country_to. So for making a simple search like from FR to US I use: @search_result = Load.find(:all, :conditions => "country_from='#{params[:country_from]}' AND country_to='#{params[:country_to]}'" ) that is fine, but I need to implement the ALL option as well, so when I make a search like from DE to ALL I get a list with all countries in country_to I image I can do it with ifs...but what would be the most efficient way to do it?

    Read the article

  • Fork a process and send data to it inside Rails

    - by taro
    I'm making a Rails application. In the one action I need to spawn a long running process. This is not a problem. I can fork new process using spawn gem or some other. But some time after process has been spawned, user must be able to pass additional data to that process. Sure, I can fork process which will listen a UNIX socket, store socket address in the HTTP session and communicate with that process using drb protocol when user will require to pass new data to process. But I think it is not best solution and it will be a problem to deploy an application to the hosting. What is the easy way to do that?

    Read the article

  • Rails attribute alias

    - by Dr1Ku
    Hi, I was just wondering if it's possible to "rename" an association in Rails. Let's assume : # An ActiveRecord Class named SomeModelASubModel (some_model_a_sub_model.rb) class SomeModelASubModel < ActiveRecord::Base has_many :some_model_a_sub_model_items end # An ActiveRecord Class named SomeModelASubModelItem (some_model_a_sub_model_item.rb) class SomeModelASubModelItem < ActiveRecord::Base belongs_to :some_model_a_sub_model end At this point, calling some_model.items, where some_model is an instance of the SomeModelASubModel Class would trigger an undefined method error. What is the best practice for making this happen though, e.g. : # With a method_alias or something, would it be possible to : some_model = SomeModelASubModel.first # for instance items = some_model.items # For the reason stated, this doesn't work, one has to call : items = some_model.some_model_a_sub_model_items Is such a shorthand possible ? Thank you in advance !

    Read the article

  • Using send_file in rails

    - by user163352
    I'm sending a ms-word file using rails. i.e when I click on a link, a doc file from tmp folder(in project) is sent. The code I'm using is @filename ="#{RAILS_ROOT}/tmp/test/test.doc" send_file(@filename , :filename => "test", :type => 'application/msword', :disposition => 'attachment', :streaming => 'true', :buffer_size => '4096') Its working, but its sending a empty file. Content is missing in the file. any suggestions??

    Read the article

  • Returning a 1x1 .gif as a response in Rails

    - by Avishai
    Hi, I'm building a Rails app that does conversion tracking on outside sites. I'd like to allow users to paste an image tag in their conversion pages (like AdWords), and whenever that image is requested, a conversion registers in my app. respond_to do |format| if @conversion.save flash[:notice] = 'Conversion was successfully created.' format.html { redirect_to(@conversion) } format.xml { render :xml => @conversion, :status => :created, :location => @conversion } format.js { render :json => @conversion, :status => :created } format.gif { head :status => :ok } else format.html { render :action => "new" } format.xml { render :xml => @conversion.errors, :status => :unprocessable_entity } end end This way, the browser gets a non-existent .gif image. Is there a better way to do this?

    Read the article

  • Rails validation issue with before_validation

    - by Chance
    I'm still fairly new to rails so I'm not sure what I'm missing here. I'm using GeoKit to geocode an address upon saving. I have a method that geocodes an address and if it fails to find it, it adds an error to the errors list. I've tested it in the console and it is failing on the geocode (presumably adding the error) but still saving successfully. acts_as_mappable before_validation_on_create :geocode_address before_validation_on_update :geocode_address validates_presence_of :street validates_presence_of :city validates_presence_of :state validates_presence_of :zip validates_presence_of :name validates_uniqueness_of :name def geocode_address geo=Geokit::Geocoders::MultiGeocoder.geocode ("#{street}, #{city}, #{state}, #{zip}") puts "geocoded: #{street}, #{city}, #{state}, #{zip}" if geo.success self.lat, self.lng = geo.lat,geo.lng else errors.add(:street, "Could not Geocode address") end puts "geo status: #{geo.success}" end Any help would be greatly appreciated, thanks :)

    Read the article

  • Rails - inheritance hierarchy of classes where a subtype can play two roles

    - by Miquel
    I need to model Owners and Rentees in an application, so you have stuff that is always owned by someone and can be rented for someone else. I first approached this problem with Single Table Inheritance because both types of person will share all attributes, so you would have a model called Person associated to a table people with Owner and Rentee inheriting from Person. The problem is that Single type inheritance discerns subtypes using a field type and therefore a record in the table can represent either an Owner or a Rentee but not both at the same time, while in the real context you can have an Owner which is renting something from another Owner and therefore that person is at the same time an Owner and a Rentee. How would you approach this problem? Would you use separated tables for owners and rentees? Is there any other type of table inheritance in Rails?

    Read the article

  • Rails: Thread won't affect database unless joined to main Thread

    - by hatboysam
    I have a background operation I would like to occur every 20 seconds in Rails given that some condition is true. It kicked off when a certain controller route is hit, and it looks like this def startProcess argId = self.id t = Thread.new do while (Argument.isRunning(argId)) do Argument.update(argId) Argument.markVotes(argId) puts "Thread ran" sleep 20 end end end However, this code does absolutely nothing to my database unless I call "t.join" in which case my whole server is blocked for a long time (but it works). Why can't the read commit ActiveRecords without being joined to the main thread? The thread calls methods that look something like def sample model = Model.new() model.save() end but the models are not saved to the DB unless the thread is joined to the main thread. Why is this? I have been banging my head about this for hours.

    Read the article

  • rails respond_to and various forms of html responses

    - by lukewendling
    I often use respond_to do |format| ... end in Rails for my Restful actions, but I don't know what the ideal solution is for handling various forms of, say, html responses. For instance, view1 that calls action A might expect back html with a list of widgets wrapped in a UL tag, while view2 expects the same list of widgets wrapped in a table. How does one Restfully express that not only do I want back an html formatted response, but I want it wrapped in a table, or in a UL, OL, options, or some other common list-oriented html tag?

    Read the article

  • Accessing two sides of a user-user relationship in rails

    - by Lowgain
    Basically, I have a users model in my rails app, and a fanship model, to facilitate the ability for users to become 'fans' of each other. In my user model, I have: has_many :fanships has_many :fanofs, :through => :fanships In my fanship model, I have: belongs_to :user belongs_to :fanof, :class_name => "User", :foreign_key => "fanof_id" My fanship table basically consists of :id, :user_id and :fanof_id. This all works fine, and I can see what users a specific user is a fan of like: <% @user.fanofs.each do |fan| %> #things <% end %> My question is, how can I get a list of the users that are a fan of this specific user? I'd like it if I could just have something like @user.fans, but if that isn't possible what is the most efficient way of going about this? Thanks!

    Read the article

  • What to use to write tests? [Rails]

    - by yuval
    I asked a question about different testing frameworks yesterday. This question can be found here. Now that I have a better understanding of the different frameworks, I have a very simple question: With a basic understanding, but very limited experience with writing tests with rails' built in testing framework (basic assertions), would it be okay for me to jump directly to testing with RSpec, Webrat, and Cucamber? Thank you! As a side note: yes, this is an opinion based question, but I feel that the input received to this question is valuable enough to the community to keep this question open. Thanks.

    Read the article

  • Log your SQL in Rails application inside unit test

    - by Phuong Nguy?n
    I want to install a logger so that I can dump all executed SQL of my rails application. Problem is, such logger is associated with AbstractAdapter which initialized very soon under test mode, and thus cannot be set by my initializer code. I try to put ActiveRecord::Base.logger = MyCustomLogger.new(STDOUT) in the end of environment.rb like someone advised but it only works when being run in console environment (kicked by script/console), not when run under test mode. I wonder if there is any way to config such logger so that I will sure to be invoked under any environment (test, development, production, console)

    Read the article

  • basic database design table on rails

    - by runcode
    I am confuse on a concept. I am doing this on rails. Is that Entity set equal to a table in the database? Is that Relationship set equal to a table in the database? Let say we have Entity set "USER" and Entity set "POST" and Entity set "COMMENT" User- can post many posts and comments as they want Post- belong to users Comments-belong to posts ,users, so comment is weak entity. SCHEMA ====== USER -id -name POST -id -user_id(FK) -comment_id (FK) COMMENT -id -user_id (FK) -post_id (FK) so USER,POST,COMMENT are tables I think. And what else is a table? And do I need a table for the relationship??

    Read the article

  • Caching Models in rails

    - by jules
    I have a rails application, with a model that is a kind of repository. The records stored in the DB for that model are (almost) never changed, but are read all the time. Also there is not a lot of them. I would like to store these records in cache, in a generic way. I would like to do something like acts_as_cached, but here are the issue I have: I can not find a decent documentation for acts as cached (neither can I find it's repository) I don't want to use memcached, but something simpler (static variable, or something like that). Do you have any idea of what gems I could use to do that ? Thanks

    Read the article

  • Multiple HTTP request - Rails

    - by bradleyg
    My application checks a number of domains to see if they are valid (approx 100). I have the following code to check a single domain: def self.test_url uri, limit = 10 if limit == 0 return get_error_messages("001") end begin url = URI.parse(uri) response = Net::HTTP.start(url.host, url.port).request_head('/') rescue SocketError => e return get_error_messages("002") end case response when Net::HTTPRedirection then test_url(response['location'], limit - 1) else return get_error_messages(response.code) end end The code checks for the response code while taking into account redirects. This works fine. The only problem I have is when I put this in a loop I want it to run in parallel. So I don't have to wait for domain 1 to respond before I can request domain 2. I have managed this in PHP using curl_multi to run the requests in parallel. Is there a similar thing I can do in Rails?

    Read the article

< Previous Page | 72 73 74 75 76 77 78 79 80 81 82 83  | Next Page >