Search Results

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

Page 79/378 | < Previous Page | 75 76 77 78 79 80 81 82 83 84 85 86  | Next Page >

  • How to set default date in date_select helper in Rails

    - by brad
    I'm trying to set up a date of birth helper in my Rails app (2.3.5). At present it is like so. <%= f.date_select :date_of_birth, :start_year => Time.now.year - 110, :end_year => Time.now.year %> This generates a perfectly functional set of date fields that work just fine but.... They default to today's date which is not ideal for a date of birth field (I'm not sure what is but unless you're running a neonatal unit today's date seems less than ideal). I want it to read Jan 1 2010 instead (or 2011 or whatever year it happens to be). Using the :default option has proven unsuccessful. I've tried many possibilities including; <%= f.date_select :date_of_birth, :default => {:year => Time.now.year, :month => 'Jan', :day => 1}, :start_year => Time.now.year - 110, :end_year => Time.now.year %> and <%= f.date_select :date_of_birth, :default => Time.local(2010,'Jan',1), :start_year => Time.now.year - 110, :end_year => Time.now.year %> None of this changes the behaviour of the first example. Does the default option actually work as described? It seems that this should be a fairly straightforward thing to do. Ta.

    Read the article

  • Parsing / Extracting Text from String in Rails?

    - by user641116
    I have a string in Rails, e.g. "This is a Twitter message. #books War & Peace by Leo Tolstoy. I love this book!", and I want to parse the text and extract only certain phrases, like "War & Peace by Leo Tolstoy". Is this a matter of using Regex and lifting the text between "#books" to "."? What if there's no structure to the message, like: "This is a Twitter message #books War & Peace by Leo Tolstoy I love this book!" or "This is a Twitter message. I love the book War & Peace by Leo Tolstoy #books" How can I reliably pull the phrase "War & Peace by Leo Tolstoy" without knowing the phrase ex ante. Are there any gems, methods, etc. that can help me do this? At the very least, what would you call what I'm trying to do? It will help me search for a solution on Google. I've tried a few searches on "parsing" with no luck.

    Read the article

  • Rails form protection questions, hidden field

    - by user284194
    I have a live rails website and I want to have a form with a lot of fields on it. I have set up validations and allowed formatting for every field. I've tested it quite a bit and it seems to catch anything I throw at it. I think it's almost ready to go live, but I want to quadruple check if there's anything else I should do to protect it. My site has a low volume of visitors, but I want it to be a safe as possible. I'd like to avoid using a captcha if I can. I've read that you can use a hidden field to protect forms against bots. Do people recommend this instead of using a captcha, or even using it with a captcha? my form is really standard: <% form_for(@entry) do |f| %> ... <%= f.submit 'Create' %> <% end %> Any suggestions or code samples would be greatly appreciated.

    Read the article

  • How will Arel affect rails' includes() 's capabilities.

    - by Tim Snowhite
    I've looked over the Arel sources, and some of the activerecord sources for Rails 3.0, but I can't seem to glean a good answer for myself as to whether Arel will be changing our ability to use includes(), when constructing queries, for the better. There are instances when one might want to modify the conditions on an activerecord :include query in 2.3.5 and before, for the association records which would be returned. But as far as I know, this is not programmatically tenable for all :include queries: (I know some AR-find-includes make t#{n}.c#{m} renames for all the attributes, and one could conceivably add conditions to these queries to limit the joined sets' results; but others do n_joins + 1 number of queries over the id sets iteratively, and I'm not sure how one might hack AR to edit these iterated queries.) Will Arel allow us to construct ActiveRecord queries which specify the resulting associated model objects when using includes()? Ex: User :has_many posts( has_many :comments) User.all(:include => :posts) #say I wanted the post objects to have their #comment counts loaded without adding a comment_count column to `posts`. #At the post level, one could do so by: posts_with_counts = Post.all(:select => 'posts.*, count(comments.id) as comment_count', :joins => 'left outer join comments on comments.post_id = posts.id', :group_by => 'posts.id') #i believe #But it seems impossible to do so while linking these post objects to each #user as well, without running User.all() and then zippering the objects into #some other collection (ugly) #OR running posts.group_by(&:user) (even uglier, with the n user queries)

    Read the article

  • Which persistent & lightweight queue messaging for cross domain (> 2) data exchange with rails integ

    - by Erwan
    Hi all, I'm looking for the right messaging system for my needs. Can you help me ? For now, there won't be a huge amount of data to process, but I don't want to be limited later ... The machines are not just web servers, so the messaging tool should be lightweight, even if processing is not very speed. When some data change on a server, all servers should have the information and process it locally. (should I create one channel per server on each of them ?) The frontend is written on Rails, so it is important, in order to simplify the development, that there is a gem / plugin to manage communications and data sent. At this time : RabbitMQ + workling seems to fit my needs. Could this be a right choice ? ActiveMQ make me afraid, because of Java (I really don't know very well Java, but it seems to me to be big CPU consumer) Others don't seem to be as mature as them. There might be lot of development using this kind of technology, so I can't go to the wrong way ! Thank you for help.

    Read the article

  • A really smart rails helper needed

    - by Stefan Liebenberg
    In my rails application I have a helper function: def render_page( permalink ) page = Page.find_by_permalink( permalink ) content_tag( :h3, page.title ) + inline_render( page.body ) end If I called the page "home" with: <%= render_page :home %> and "home" page's body was: <h1>Home<h1/> bla bla <%= render_page :about %> <%= render_page :contact %> I would get "home" page, with "about" and "contact", it's nice and simple... right up to where someone goes and changes the "home" page's content to: <h1>Home<h1/> bla bla <%= render_page :home %> <%= render_page :about %> <%= render_page :contact %> which will result in a infinite loop ( a segment fault on webrick )... How would I change the helper function to something that won't fall into this trap? My first attempt was along the lines of: @@list = [] def render_page( permalink ) unless @@list.include?(permalink) @@list += [ permalink ] page = Page.find_by_permalink result = content_tag( :h3, page.title ) + inline_render( page.body ) @@list -= [ permalink ] return result else content_tag :b, "this page is already being rendered" end end which worked on my development environment, but bombed out in production... any suggestions? Thank You Stefan

    Read the article

  • Rails model relations depending on count of nested relations

    - by Lowgain
    I am putting together a messaging system for a rails app I am working on. I am building it in a similar fashion to facebook's system, so messages are grouped into threads, etc. My related models are: MsgThread - main container of a thread Message - each message/reply in thread Recipience - ties to user to define which users should subscribe to this thread Read - determines whether or not a user has read a specific message My relationships look like class User < ActiveRecord::Base #stuff... has_many :msg_threads, :foreign_key => 'originator_id' #threads the user has started has_many :recipiences has_many :subscribed_threads, :through => :recipiences, :source => :msg_thread #threads the user is subscribed to end class MsgThread < ActiveRecord::Base has_many :messages has_many :recipiences belongs_to :originator, :class_name => "User", :foreign_key => "originator_id" end class Recipience < ActiveRecord::Base belongs_to :user belongs_to :msg_thread end class Message < ActiveRecord::Base belongs_to :msg_thread belongs_to :author, :class_name => "User", :foreign_key => "author_id" end class Read < ActiveRecord::Base belongs_to :user belongs_to :message end I'd like to create a new selector in the user sort of like: has_many :updated_threads, :through => :recipiencies, :source => :msg_thread, :conditions => {THREAD CONTAINS MESSAGES WHICH ARE UNREAD (have no 'read' models tying a user to a message)} I was thinking of either writing a long condition with multiple joins, or possibly writing giving the model an updated_threads method to return this, but I'd like to see if there is an easier way first. Any ideas? Also, if there is something fundamentally wrong with my structure for this functionality let me know! Thanks!!

    Read the article

  • A few questions about a Rails model for a simple addressbook app

    - by user284194
    I have a Rails application that lists information about local services. My objectives for this model are as follows: 1. Require the name and tag_list fields. 2. Require one or more of the tollfreephone, phone, phone2, mobile, fax, email or website fields. 3. If the paddress field has a value, then encode it with the Geokit plugin. Here is my entry.rb model: class Entry < ActiveRecord::Base validates_presence_of :name, :tag_list validates_presence_of :tollfreephone or :phone or :phone2 or :mobile or :fax or :email or :website acts_as_taggable_on :tags acts_as_mappable :auto_geocode=>{:field=>:paddress, :error_message=>'Could not geocode physical address'} before_save :geocode_paddress validate :required_info def required_info unless phone or phone2 or tollfreephone or mobile or fax or email or website errors.add_to_base "Please have at least one form of contact information." end end private def geocode_paddress #if paddress_changed? geo=Geokit::Geocoders::MultiGeocoder.geocode (paddress) errors.add(:paddress, "Could not Geocode address") if ! geo.success self.lat, self.lng = geo.lat,geo.lng if geo.success #end end end Requiring name and tag_list work, but requiring one (or more) of the tollfreephone, phone, phone2, mobile, fax, email or website fields does not. As for encoding with Geokit, in order to save a record with the model I have to enter an address. Which is not the behavior I want. I would like it to not require the paddress field, but if the paddress field does have a value, it should encode the geocode. As it stands, it always tries to geocode the incoming entry. The commented out "if paddress_changed?" was not working and I could not find something like "if paddress_exists?" that would work. Help with any of these issues would be greatly appreciated. I posted three questions pertaining to my model because I'm not sure if they are preventing each other from working. Thank you for reading my questions.

    Read the article

  • android/rails multipart upload problem

    - by trioglobal
    My problem is that I try to upload an image and some text values to an rails server, and the text values end up as files, insted of just param values. How the post looks on the server Parameters: {"action"="create", "controller"="problems", "problem"={"lon"=#File:/tmp/RackMultipart20100404-598-8pi1vj-0, "photos_attributes"={"0"={"image"=#File:/tmp/RackMultipart20100404-598-pak6jk-0}}, "subject"=#File:/tmp/RackMultipart20100404-598-nje11p-0, "category_id"=#File:/tmp/RackMultipart20100404-598-ijy1oo-0, "lat"=#File:/tmp/RackMultipart20100404-598-1a7140w-0, "email"=#File:/tmp/RackMultipart20100404-598-1b7w6jp-0}} part of the android code try { File file = new File(Environment.getExternalStorageDirectory(), "FMS_photo.jpg"); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://homepage.com/path"); FileBody bin = new FileBody(file); Charset chars = Charset.forName("UTF-8"); MultipartEntity reqEntity = new MultipartEntity(); //reqEntity.addPart("problem[subject]", subject); reqEntity.addPart("problem[photos_attributes][0][image]", bin); reqEntity.addPart("problem[category_id]", new StringBody("17", chars)); //.... post.setEntity(reqEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { resEntity.consumeContent(); } return true; } catch (Exception ex) { //Log.v(LOG_TAG, "Exception", ex); globalStatus = UPLOAD_ERROR; serverResponse = ""; return false; } finally { }

    Read the article

  • Ruby-on-rails: routing problem: controller action looks for show when it should look for finalize

    - by cbrulak
    background: trying to use the twitter gem for ruby-on-rails. in routes: map.resources :twitter_sessions map.finalize_twitter_sessions 'twitter_sessions/finalize', :controller => 'twitter_sessions', :action => 'finalize' (twitter_sessions is the controller for the twitter sessions in my app). The view has one file new.html.erb and is very simple: <% form_tag(twitter_sessions_path) do |f| %> <p><%= submit_tag "twitter!" %></p> <% end %> and the twitter_sessions_controller.rb: def new end def create oauth.set_callback_url(finalize_twitter_sessions_url) session['rtoken'] = oauth.request_token.token session['rsecret'] = oauth.request_token.secret redirect_to oauth.request_token.authorize_url end def destroy reset_session redirect_to new_session_path end def finalize oauth.authorize_from_request(session['rtoken'], session['rsecret'], params[:oauth_verifier]) profile = Twitter::Base.new(oauth).verify_credentials session['rtoken'] = session['rsecret'] = nil session[:atoken] = oauth.access_token.token session[:asecret] = oauth.access_token.secret sign_in(profile) redirect_back_or root_path end However, after I click the "twitter" button, I get this error: 401 Unauthorized .../gems/oauth-0.3.6/lib/oauth/consumer.rb:200:in `token_request' .../gems/oauth-0.3.6/lib/oauth/consumer.rb:128:in `get_request_token' .../gems/twitter-0.9.2/lib/twitter/oauth.rb:32:in `request_token' .../gems/twitter-0.9.2/lib/twitter/oauth.rb:25:in `set_callback_url' app/controllers/twitter_sessions_controller.rb:7:in `create' If I go to the finalize url, http://localhost:3000/twitter_sessions/finalize, directly, I get this error: Unknown action No action responded to show. Actions: create, destroy, finalize, isLoggedInToBeta, login_required, and new Any ideas? Thanks

    Read the article

  • Rails undefined method 'generated_methods' for nil:NilClass

    - by mike
    Okay so I was just starting this rails app and generated my first model ruby script/generate model Grid req:string class:string ctitle:string credits:float grade:string pass:boolean created my table rake db:migrate (in C:/Users/Michael/InstantRails/rails_apps/studentGrid) == CreateGrids: migrating ==================================================== -- create_table(:grids) - 0.0150s == CreateGrids: migrated (0.0150s) =========================================== and went to the console to add some data to my table Grid = Grid(id: integer, req: string, class: string, ctitle: string, credits: float, grade: string, pass: boolean, created_at: datetime, updated_at: datetime) Grid.create(:req="Math Elective", :class="Math 111", :ctitle="Calculus I", :credits=3.0) Pretty standard I thought, but then I get this error and I don't understand why NoMethodError: undefined method 'generated_methods' for nil:NilClass from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesup port-2.3.5/lib/active_support/whiny_nil.rb:52:inmethod_missing' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/attribute_methods.rb:352:in respond_to?' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/base.rb:2746:inattributes=' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/base.rb:2742:in each' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/base.rb:2742:inattributes=' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/base.rb:2438:in initialize' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/base.rb:721:innew' from C:/Users/Michael/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerec ord-2.3.5/lib/active_record/base.rb:721:in `create' from (irb):2 from :0

    Read the article

  • Rails paginate array items one-by-one instead of page-by-page

    - by hnovick
    Hi Guys, I have a group of assets, let's call them "practitioners". I'm displaying these practitioners in the header of a calendar interface. There are 7 columns to the calendar. 7 columns = 7 practitioners per view/page. Right now: if the first page shows you practitioners 1-7, when you go the next page you will see practitioners 8-15, next page 16-23, etc. etc. i am wondering how to page the practitioners so that if the first page shows you practitioners 1-7, the next page will show you practitioners 2-8, then 3-9, etc. etc. i would greatly appreciate any help you can offer. here is the rails code i am working with. best regards, harris novick # get the default sort order sort_order = RESOURCE_SORT_ORDER # if we've been given asset ids, start our list with them unless params[:asset_ids].blank? params[:asset_ids] = params[:asset_ids].values unless params[:asset_ids].is_a?(Array) sort_order = "#{params[:asset_ids].collect{|id| "service_provider_resources.id = #{id} DESC"}.join(",")}, #{sort_order}" end @asset_set = @provider.active_resources(:include => {:active_services => :latest_approved_version}).paginate( :per_page => RESOURCES_IN_DAY_VIEW, :page => params[:page], :order => sort_order )

    Read the article

  • Rails 1.0 - Using composed_of gives me a wrong number of arguments (1 for 5) error

    - by Tristan Havelick
    I am developing a Rails 1.0 application (I can't upgrade, it's a strange situation) for which I am trying to use the :composed_of functionality. I have a class called StreetAddress: class StreetAddress attr_reader :address, :address2, :city, :state_id, :zip_code def initialize(address, address2, city, state_id, zip_code) @address = address @address2 = address2 @city = city @state_id = state_id @zip_code = zip_code end end and a model class called Hotel class Hotel < ActiveRecord::Base composed_of :street_address # ... end which has columns: "id", "brand_id", "code", "location_name", "address", "address2", "city", "state_id", "zip_code", "phone_number", "phone_ext", "fax_number", "time_zone", "url", "room_service_email", "manager_name", "manager_email" However when I try to access the aggregation I get an error: >> h = Hotel.find(1) => #<Hotel:0x38ad718 @attributes={"fax_number"=>"1-623-420-0124", "city"=>"Twin Falls", "address2"=>"285", "brand_id"=>"1", "code"=>"XZWUXUSZ", "manager_email"= >"[email protected]", "url"=>"http://www.xycdkzolukfvu.hom", "ph one_number"=>"1-805-706-9995", "zip_code"=>"72436", "phone_ext"=>"48060", "id"=> "1", "manager_name"=>"Igor Mcdowell", "room_service_email"=>"Duis.risus@Donecvit ae.ca", "time_zone"=>"America/Boise", "state_id"=>"15", "address"=>"P.O. Box 457 , 7405 Dignissim Avenue", "location_name"=>"penatibus et magnis"}> >> h.street_address ArgumentError: wrong number of arguments (1 for 5) from (eval):3:in `initialize' from (eval):3:in `new' from (eval):3:in `street_address' from (irb):6 Why?

    Read the article

  • ruby, rails, railscasts example I messed up

    - by Sam
    If you saw the railscasts on nested forms this is the helper method to create links dynamically. However, after I upgraded to ruby 1.9.2 and rails 3 this doesn't work and I have now idea why. def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")) end here is the javascript function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g") $(link).up().insert({ before: content.replace(regexp, new_id) }); } When I view source this is how the link is getting rendered: <p><a href="#" onclick="add_fields(this, &quot;dimensions&quot;, &quot;&quot;); return false;">Add Dimension</a></p> so &quot;&quot; is not the correct information to build a new template and something is going on with how the string for fields is getting set. such as fields= f.fields_for

    Read the article

  • Ruby on Rails script/console printing more than expected

    - by Lloyd
    I have a simple model setup in my Ruby on Rails app. (User {name, username, lat, lon}) and am writing a basic extension to the model. I would like the method to return users within a certain distance. It all works just fine in the page view, but as I am debugging I would like to work through some testing using the script/console. My question: It seems to be printing to the screen the entire result set when I run it from the command line and script/console. My model: class User < ActiveRecord::Base def distance_from(aLat, aLon) Math.sqrt((69.1*(aLat - self.lat))**2 + (49*(aLon - self.lon))**2 ) end def distance_from_user(aUser) distance_from(aUser.lat, aUser.lon) end def users_within(distance) close_users = [] users = User.find(:all) users.each do |u| close_users << u if u.distance_from_user(self) < distance end return close_users end end and from the command line I am running >> u = User.find_by_username("someuser") >> print u.users_within(1) So, I guess I would like to know why it's printing the whole result set, and if there is a way to suppress it so as to only print what I want?

    Read the article

  • How to customize RESTful Routes in Rails (basics)

    - by viatropos
    I have read through the Rails docs for Routing, Restful Resources, and the UrlHelper, and still don't understand best practices for creating complex/nested routes. The example I'm working on now is for events, which has_many rsvps. So a user's looking through a list of events, and clicks register, and goes through a registration process, etc. I want the urls to look like this: /events /events/123 # possible without title, like SO /events/123/my-event-title # canonical version /events/my-category/123/my-event-title # also possible like this /events/123/my-event-title/registration/new ... and all the restful nested resouces. Question is, how do I accomplish this with the minimal amount of code? Here's what I currently have: map.resources :events do |event| event.resources :rsvps, :as => "registration" end That gets me this: /events/123/registration What's the best way to accomplish the other 2 routes? /events/123/my-event-title # canonical version /events/my-category/123/my-event-title # also possible like this Where my-category is just an array of 10 possible types the event can be. I've modified Event#to_param to return "#{self.id.to_s}-#{self.title.parameterize}", but I'd prefer to have /id/title with the whole canonical-ness

    Read the article

  • Rails: Oracle constraint violation

    - by justinbach
    I'm doing maintenance work on a Rails site that I inherited; it's driven by an Oracle database, and I've got access to both development and production installations of the site (each with its own Oracle DB). I'm running into an Oracle error when trying to insert data on the production site, but not the dev site: ActiveRecord::StatementInvalid (OCIError: ORA-00001: unique constraint (DATABASE_NAME.PK_REGISTRATION_OWNERSHIP) violated: INSERT INTO registration_ownerships (updated_at, company_ownership_id, created_by, updated_by, registration_id, created_at) VALUES ('2006-05-04 16:30:47', 3, NULL, NULL, 2920, '2006-05-04 16:30:47')): /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:221:in `execute' app/controllers/vendors_controller.rb:94:in `create' As far as I can tell (I'm using Navicat as an Oracle client), the DB schema for the dev site is identical to that of the live site. I'm not an Oracle expert; can anyone shed light on why I'd be getting the error in one installation and not the other? Incidentally, both dev and production registration_ownerships tables are populated with lots of data, including duplicate entries for country_ownership_id (driven by index PK_REGISTRATION_OWNERSHIP). Please let me know if you need more information to troubleshoot. I'm sorry I haven't given more already, but I just wasn't sure which details would be helpful.

    Read the article

  • Rails, Apache2 on Ubuntu (karmic) deployment

    - by Steve
    I just need some clarification on a couple of files. My site has an admin subdomain and SSL in addition to the normal *:80 details found in the virtual hosts. My question(s): Do I need to specify a 1) ServerName and 2) DocumentRoot in: /etc/apache2/apache2.conf? I currently enable my site from this directory: /etc/apache2/sites-available/site Here are the contents of my site file in the above directory (/etc/apache2/sites-available/site): <VirtualHost *:80> ServerName www.site.com ServerAlias www.site.com DocumentRoot /home/user/public_html/site/current/public RailsAllowModRewrite off <directory "/home/user/public_html/site/current/public"> Order allow,deny Allow from all </directory> </VirtualHost> <VirtualHost *:80> ServerName www.site.com ServerAlias admin.site.com DocumentRoot /home/user/public_html/site/current/public RailsAllowModRewrite off <directory "/home/user/public_html/site/current/public"> Order allow,deny Allow from all </directory> </VirtualHost> <VirtualHost *:443> ServerName www.site.com ServerAlias www.site.com # SSL releated SSLEngine on SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire SSLCertificateFile /path/to/site.com.crt SSLCertificateChainFile /path/to/bundle.crt SSLCertificateKeyFile /path/to/site.key # Used by rails RequestHeader set X_FORWARDED_PROTO "https" </VirtualHost> Do you see anything wrong?

    Read the article

  • Rendering 'belongs_to" in index view question - Ruby on Rails

    - by bgadoci
    I have created a simple blog application with Ruby on Rails. The applications consists of two tables, posts and comments. Comments belongs_to :post and posts has_many :comments. I created posts table with the following columns: title:string, body:text. I created the comments table with the following columns: body:text post_id:integer name:string email:string In the /views/comments/index.html.erb display I would like to show a listing of all comments w/ the post title as well. Currently, the index view only displays post_id, body, name, email. How do I replace the post_id column with the corresponding post title? Here is my code: CommentsController Index action: def index @comments = Comment.all :order => "created_at DESC" respond_to do |format| format.html # index.html.erb format.xml { render :xml => @comments } format.json { render :json => @comments } format.atom end end /views/comments/index.html.erb <h1>Listing comments</h1> <table> <tr> <th>Post</th> <th>Body</th> </tr> <% @comments.each do |comment| %> <tr> <td><%=h comment.post_id %></td> <td><%=h comment.body %></td> <td><%=h comment.name %></td> <td><%=h comment.email %></td> </tr> <% end %> </table> <br />

    Read the article

  • Beginner's guide for rails

    - by piemesons
    Hello friends i need a book/ tutorials for rails without using scoffold. All the books mentioned in the other questions are creating some depot application or etc using scaffold and then explaining things. I believe in the thing that creating big depot is worthless when you are not getting anything. All of my frnds are suggesting me to go for this pragmatic book. look i understand the book is good but i m not getting the proper things. I got the logic cause i m good in php doctrine. asp.net c c++ so i m getting the things but i m not feeling confident. I want to have a another book. Can anybody suggest me some other books. I m saying this cause it really feels good when u create a simple form and insert the values in db and u can retreive those values and MOST IMP you can explain the whole logic of the that small form application instaed of that colorfull Depot application in which things are done with scaffold and u r not getting the thing and u are confused abt the real picture.

    Read the article

  • rails: has_many :through validation?

    - by ramonrails
    Rails 2.1.0 (Cannot upgrade for now due to several constraints) I am trying to achieve this. Any hints? A project has many users through join model A user has many projects through join model Admin class inherits User class. It also has some Admin specific stuff. Admin like inheritance for Supervisor and Operator Project has one Admin, One supervisor and many operators. Now I want to 1. submit data for project, admin, supervisor and operator in a single project form 2. validate all and show errors on the project form. Project has_many :projects_users ; has_many :users, :through => :projects_users User has_many :projects_users ; has_many :projects, :through => :projects_users ProjectsUser = :id integer, :user_id :integer, :project_id :integer, :user_type :string ProjectUser belongs_to :project, belongs_to :user Admin < User # User has 'type:string' column for STI Supervisor < User Operator < User Is the approach correct? Any and all suggestions are welcome.

    Read the article

  • A really smart rails helper needed

    - by Stefan Liebenberg
    In my rails application I have a helper function: def render_page( permalink ) page = Page.find_by_permalink( permalink ) content_tag( :h3, page.title ) + inline_render( page.body ) end If I called the page "home" with: <%= render_page :home %> and "home" page's body was: <h1>Home<h1/> bla bla <%= render_page :about %> <%= render_page :contact %> I would get "home" page, with "about" and "contact", it's nice and simple... right up to where someone goes and changes the "home" page's content to: <h1>Home<h1/> bla bla <%= render_page :home %> <%= render_page :about %> <%= render_page :contact %> which will result in a infinite loop ( a segment fault on webrick )... How would I change the helper function to something that won't fall into this trap? My first attempt was along the lines of: @@list = [] def render_page( permalink ) unless list.include?(permalink) @@list += [ permalink ] page = Page.find_by_permalink content_tag( :h3, page.title ) + inline_render( page.body ) @@list -= [ permalink ] else content_tag :b, "this page is already being rendered" end end which worked on my development environment, but bombed out in production... any suggestions? Thank You Stefan

    Read the article

  • Changing href atributes with nokogiri and ruby on rails

    - by fool
    Hi, I Have a HTML document with links links, for exemple: <html> <body> <ul> <li><a href="http://someurl.com/etc/etc">teste1</a></li> <li><a href="http://someurl.com/etc/etc">teste2</a></li> <li><a href="http://someurl.com/etc/etc">teste3</a></li> <ul> </body> </html> I want with Ruby on Rails, with nokogiri or some other method, to have a final doc like this: <html> <body> <ul> <li><a href="http://myproxy.com/?url=http://someurl.com/etc/etc">teste1</a></li> <li><a href="http://myproxy.com/?url=http://someurl.com/etc/etc">teste2</a></li> <li><a href="http://myproxy.com/?url=http://someurl.com/etc/etc">teste3</a></li> <ul> </body> </html> What's the best strategy to achieve this?

    Read the article

  • Net::SMTPFatalError in rails 2.3.4

    - by Brian Roisentul
    I'm getting the following error when trying to send email on rails 2.3.4(it worked on 2.3.2) using action_mailer_tls plugin: Net::SMTPFatalError in UsersController#create 555 5.5.2 Syntax error. w3sm66205164ybi.9 C:/Program Files (x86)/NetBeans 6.8/ruby2/jruby-1.4.0/lib/ruby/1.8/net/smtp.rb:930:in `check_response' C:/Program Files (x86)/NetBeans 6.8/ruby2/jruby-1.4.0/lib/ruby/1.8/net/smtp.rb:899:in `getok' C:/Program Files (x86)/NetBeans 6.8/ruby2/jruby-1.4.0/lib/ruby/1.8/net/smtp.rb:828:in `mailfrom' C:/Program Files (x86)/NetBeans 6.8/ruby2/jruby-1.4.0/lib/ruby/1.8/net/smtp.rb:653:in `send_message' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:683:in `perform_delivery_smtp' C:/Program Files (x86)/NetBeans 6.8/ruby2/jruby-1.4.0/lib/ruby/1.8/net/smtp.rb:526:in `start' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:681:in `perform_delivery_smtp' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:523:in `deliver!' C:/Ruby/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:395:in `method_missing' D:/Proyectos/Cursometro/www/app/models/user_observer.rb:3:in `after_create' D:/Proyectos/Cursometro/www/app/controllers/users_controller.rb:221:in `create_new_user' D:/Proyectos/Cursometro/www/app/controllers/users_controller.rb:101:in `create' This has happened after I changed the following line at action_mailer/

    Read the article

  • Switching from form_for to remote_form_for problems with submit changes in Rails

    - by Matthias Günther
    Hi there, another day with Rails and today I want to use Ajax. linkt_remote_link for changing a text was pretty easy so I thought it would also be easy to switch my form_for loop just to an ajax request form with remote_form_for, but the problem with the remote_form_for is that it doesn't save my changes? Here the code that worked: <% form_for bill, :url => {:action => 'update', :id => bill.id} do |f| %> # make the processing e.g. displaying texfields and so on <%= submit_tag 'speichern'%> It produces the following html code: <form action="/adminbill/update/58" class="edit_bill" id="edit_bill_58" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div> <!-- here the html things for the forms --> <input class="button" name="commit" type="submit" value="speichern" /> Here the code which don't save me the changes and submit them: <% remote_form_for bill, :url => {:action => 'update', :id => bill.id} do |f| %> # make the processing e.g. displaying texfields and so on <%= submit_tag 'speichern'%> It produces the following html code: <form action="/adminbill/update/58" class="edit_bill" id="edit_bill_58" method="post" onsubmit="$.ajax({data:$.param($(this).serializeArray()), dataType:'script', type:'post', url:'/adminbill/update/58'}); return false;"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div> <!-- here the html things for the forms --> <input class="button" name="commit" type="submit" value="speichern" /> I don't know if I have to consider something special when using remote_form_for (see remote_form_for)

    Read the article

< Previous Page | 75 76 77 78 79 80 81 82 83 84 85 86  | Next Page >